97jaz / gregor

Date and time library for Racket
45 stars 10 forks source link

add posix->moment to public api #50

Closed mxork closed 2 years ago

mxork commented 2 years ago

addressing https://github.com/97jaz/gregor/issues/43

mxork commented 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.

97jaz commented 2 years ago

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).

97jaz commented 2 years ago

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.)

mxork commented 2 years ago

Sorry for the force-push thrash; I had some formatting diffs that I thought were distracting.

diff:

Let me know if you need anything else added. FWIW, I really appreciate your work on gregor.

97jaz commented 2 years ago

Thanks @mxork, looks great!