Closed mxork closed 2 years ago
Sorry, this PR needs an update. Didn't realize posix->moment takes an offset.
Though, why does it take an offset? As mentioned in the referenced issue, posix time is defined as an offset from a particular moment.
As mentioned in the referenced issue, posix time is defined as an offset from a particular moment.
Yes, posix time is seconds since the start of Jan. 1, 1970 UTC. But a moment
in gregor does not have to use UTC; it can use an arbitrary IANA time zone or second offset from UTC. So when you construct a moment, you need to tell gregor
what that time zone or offset should be. For example, you could convert posix time 0 into a moment
that represents midnight on Jan. 1, 1970 UTC, or you could convert it into one that represents Dec. 31, 1969 at 19:00 in America/New_York. (These both represent the same actual moment in time, of course, but they describe that moment differently. They will be moment=?
but not equal?
, by the way.)
As a rule, gregor
uses the value of current-timezone
as the default TZ for these kinds of operations. posix->moment
as it currently exists doesn't do that, probably because it's not a public function (though it's been long enough that I don't know what was going through my head at the time).
At any rate, I think the contract should be:
(->* (real?) (tz/c) moment?)
assuming I have the syntax right. That is, I think it should take a real
and, optionally, a time zone or UTC offset and return a moment
. It shouldn't return a datetime
, which is what your documentation says.
Also, the function itself would need to be modified to make the tz/c
argument optional.
(And there need to be tests.)
Sorry for the force-push thrash; I had some formatting diffs that I thought were distracting.
diff:
(current-timezone)
; didn't make it a keyword #:tz
argument to avoid breaking existing callsposix->moment
using some well known times from https://en.wikipedia.org/wiki/Unix_timeposix->datetime
while I was at itLet me know if you need anything else added. FWIW, I really appreciate your work on gregor.
Thanks @mxork, looks great!
addressing https://github.com/97jaz/gregor/issues/43