Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/time.carp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@
(Maybe.Nothing)
(Maybe.Just @&Timezone.utc)))
"date with UTC timezone is utc")
(assert-true test
(Datetime.utc?
&(Datetime.init 2024
3
15
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Just (Timezone.init @"utc" 0l false))))
"date with lowercase utc timezone is utc")
(assert-true test
(Datetime.utc?
&(Datetime.init 2024
3
15
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Nothing)
(Maybe.Just (Timezone.init @"Utc" 0l false))))
"date with mixed case Utc timezone is utc")
(assert-false test
(Datetime.utc?
&(Datetime.init 2024
Expand Down
11 changes: 7 additions & 4 deletions time.carp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,15 @@ timestamp `ts`, i.e. the number of seconds elapsed since the 1st of January,
(Maybe.Nothing)
(Maybe.Nothing))))

; TODO should this be case-insensitive?
(doc utc? "checks whether the timezone of the `Datetime` `dt` is UTC. It will
also return true if the timezone is not set.")
(doc utc? "checks whether the timezone of the `Datetime` `dt` is UTC. The
timezone name comparison is case-insensitive. It will also return true if the
timezone is not set.")
(defn utc? [dt]
(or (Maybe.nothing? (tz dt))
(= &Timezone.utc &(Maybe.from @(tz dt) (Timezone.zero)))))
(let [t (Maybe.from @(tz dt) (Timezone.zero))]
(and
(= &(String.ascii-to-lower (Timezone.name &t)) "utc")
(and (= @(Timezone.delta &t) 0l) (not @(Timezone.dst? &t)))))))

(doc isoformat "returns the ISO format for the `Datetime` `dt`.

Expand Down
Loading