Milliseconds since 1970-01-01T00:00:00Z.
Integer arithmetic throughout, via the civil-calendar conversion
below, so the result is exact and identical on every compiler. The
utc_offset_min field is subtracted, so a local time and the same
instant expressed in UTC give the same answer.
A datetime_t whose utc_offset_known is false has no UTC instant
to compute; this returns the value its zero offset implies, which is
the local time read as though it were UTC. There is no error channel
here – the function is pure and total – so a caller that may be
handed such a value must test the flag itself.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(datetime_t), | intent(in) | :: | dt |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private | :: | days |
pure function unix_time_ms(dt) result(ms) !! Milliseconds since 1970-01-01T00:00:00Z. !! !! Integer arithmetic throughout, via the civil-calendar conversion !! below, so the result is exact and identical on every compiler. The !! `utc_offset_min` field is subtracted, so a local time and the same !! instant expressed in UTC give the same answer. !! !! A `datetime_t` whose `utc_offset_known` is false has no UTC instant !! to compute; this returns the value its zero offset implies, which is !! the local time read as though it were UTC. There is no error channel !! here -- the function is `pure` and total -- so a caller that may be !! handed such a value must test the flag itself. type(datetime_t), intent(in) :: dt integer(int64) :: ms integer(int64) :: days days = days_from_civil(int(dt%year, int64), int(dt%month, int64), int(dt%day, int64)) ms = days*MS_PER_DAY & + int(dt%hour, int64)*MS_PER_HOUR & + int(dt%minute, int64)*MS_PER_MINUTE & + int(dt%second, int64)*MS_PER_SECOND & + int(dt%millisecond, int64) & - int(dt%utc_offset_min, int64)*MS_PER_MINUTE end function unix_time_ms