reazen / relude-eon

A datetime library for the ages in ReasonML
MIT License
12 stars 4 forks source link

Add InstantUTC #7

Closed mlms13 closed 5 years ago

mlms13 commented 5 years ago

I'm not 100% sure what this should look like, since its shape is really just LocalDateTime. InstantUTC should also be a member of Eq and Ord, and its implementations will look exactly the same. The only real difference is the logic when converting to/from Instant (where LocalDateTime simply drops/adds an offset, while InstantUTC adjusts the underlying datetime to accommodate the new offset).

E.g.:

let dt = LocalDateTime.makeClamped(
  ~year=2019,
  ~month=Aug,
  ~day=11,
  ~hour=10,
  ~minute=45,
  ()
);

// 2019-08-11T10:45:00-06:00
Instant.fromLocalDateTime(~offset=-360, dt) |> Instant.formatISO;

// 2019-08-11T16:45:00-06:00
Instant.fromInstantUTC(~offset=-360, dt) |> Instant.formatISO;