Created
August 14, 2013 11:20
-
-
Save foxracle/6230145 to your computer and use it in GitHub Desktop.
use local time instead of UTC format when insert into mongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fluent/plugin/out_mongo' | |
module Fluent | |
class MongoTimezoneOutput < MongoOutput | |
Plugin.register_output('mongo_timezone', self) | |
# offset to UTC (in hour) | |
config_param :utcoffset, :integer, :default => 0 | |
def collect_records(chunk) | |
records = [] | |
chunk.msgpack_each { |time, record| | |
# add utcoffset to timestamp of UTC to pretend to act as your timezone | |
record[@time_key] = Time.at(time || record[@time_key]) + @utcoffset * 3600 if @include_time_key | |
records << record | |
} | |
records | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment