Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dcy opened this issue Nov 19, 2015 · 3 comments
Open

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

dcy opened this issue Nov 19, 2015 · 3 comments

Comments

@dcy
Copy link

dcy commented Nov 19, 2015

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
Copy link
Author

dcy commented Nov 19, 2015

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.

@choptastic
Copy link
Owner

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
Copy link
Owner

The GMT+8 bug has been filed here: dmitryme/erlang_localtime#26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants