Note that there are some explanatory texts on larger screens.

plurals
  1. POErlang: timestamp with time zone arithmetics
    text
    copied!<p>What is the best way to add/subtract units to/from specific timestamp with respect to time zone in Erlang? </p> <p>From what I've found, calendar of stdlib can work with either local or UTC time zone, no more. Moreover, arithmetics is recommended to do in UTC time zone only (the reason is obvious). </p> <p>What should I do if, for instance, I need to add 1 month to {{2011,3,24},{11,13,15}} in, let's say, CET (Central European Time) and local (system) time zone is not CET? That is not even the same as converting this timestamp to UTC, adding 31 * 24 * 60 * 60 seconds and converting back to CET (that will give {{2011,4,24},{12,13,15}} instead of {{2011,4,24},{11,13,15}}). By the way we can't do even such a thing if CET is not local time zone with stdlib. </p> <p>The answers I found googling are:</p> <ol> <li>setenv to make local time zone = needed time zone (that is very ugly first of all; then it will only allow to convert needed time zone to utc and do arithmetics respective to utc, not the needed time zone)</li> <li>open_port to linux date util and do arithmetics there (not that ugly; rather slow; needs some parsing, because the protocol between erlang and date will be textual)</li> <li>port driver or erl_interface to C using its standard library (not ugly at all; but I didn't find ready to use solution and I'm not that good at C to write one)</li> </ol> <p>The ideal solution would be something written in Erlang using OS timezone info, but I didn't find any. </p> <p>Now I'm stuck to solution 2 (open_port to date util). Is there a better way? </p> <p>Thanks in advance. </p> <p>P. S. There was a similar issue, but no good answer there <a href="https://stackoverflow.com/questions/1258495/time-zone-list-issue">Time zone list issue</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload