diff --git a/README.md b/README.md index 008b50f..1a09e0c 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,7 @@ DB.open "mysql://root@localhost/test" do |db| end end end -``` \ No newline at end of file +``` +#### Time Zone +To change the time zone that this library uses (defaults to UTC), set a DB_TIME_ZONE env var to the desired location. +Example: `DB_TIME_ZONE="Europe/Berlin"` diff --git a/src/mysql.cr b/src/mysql.cr index ceaff6b..41de6d9 100644 --- a/src/mysql.cr +++ b/src/mysql.cr @@ -12,6 +12,10 @@ module MySql alias Any = DB::Any | Int16 | Int8 | Time::Span + def self.time_zone + ENV.has_key?("DB_TIME_ZONE") ? Time::Location.load(ENV["DB_TIME_ZONE"]) : Time::Location::UTC + end + # :nodoc: - TIME_ZONE = Time::Location::UTC + TIME_ZONE = MySql.time_zone end