qdate icon indicating copy to clipboard operation
qdate copied to clipboard

qdate:set_timezone("UTC+8")'s error

Open dcy opened this issue 9 years ago • 3 comments

qdate:set_timezone("UTC+8"),
qdate:to_unixtime(calendar:local_time())

will raise error:

([email protected])32> qdate:to_unixtime(calendar:local_time()).
** exception error: no function clause matching calendar:date_to_gregorian_days(error) (calendar.erl, line 124)
     in function  calendar:datetime_to_gregorian_seconds/1 (calendar.erl, line 137)
     in call from qdate:to_unixtime/2 (src/qdate.erl, line 294)

qdate:to_date("UTC+8", util:unixtime()). will be "{error,unknown_tz}"

"GMT" works

dcy avatar Nov 19 '15 09:11 dcy

And another error:

Eshell V6.3  (abort with ^G)
1> qdate:start().
ok
2> calendar:local_time().
{{2015,11,19},{17,27,37}}
3> qdate:to_date(qdate:unixtime()).
{{2015,11,19},{9,28,1}}

it will be 8 hours difference.

dcy avatar Nov 19 '15 09:11 dcy

Hi,

Thanks for the report.

That it crashes with "UTC+6" is definitely an error, and I will get that fixed.

Apparently it doesn't like "UTC+6", but "GMT+6" is fine, but does reveal a bug in erlang_localtime with respect to "GMT+-X" format in that it seems to increment and decrement the minutes rather than hours. That's another problem.

As for the calendar:local_time() thing, that is not actually an error. Unless you've set a default timezone using the config key default_timezone (or at runtime with application:set_env(qdate, default_timezone, XYZ)), or set for the specific process using qdate:set_timezone(XYZ), then you will get that discrepancy.

qdate assumes GMT unless you've set one of the above settings to change the timezone. Conversely, calendar:local_time() returns the current machine's timezone local time, while qdate:to_date() will convert any times to the currently set timezone (in the above example, GMT).

For now, I recommend using the canonical names for timezones, either the abbreviations (like "CST" for "Central Standard Time"), or the location names, like "Asia/Brunei".

choptastic avatar Nov 19 '15 16:11 choptastic

The GMT+8 bug has been filed here: https://github.com/dmitryme/erlang_localtime/issues/26

choptastic avatar Nov 19 '15 16:11 choptastic