Skip to content

Commit

Permalink
Split DateTime into Date and Time types
Browse files Browse the repository at this point in the history
The DateTime type is now an inline type built on top of two newly
introduced types: std.time.Date and std.time.Time. The Date type stores
the date components without a timezone, while the Time type stores the
time components, also without a timezone. The UTC offset in turn is
stored in the DateTime type.

In addition, DateTime.local replaces the old DateTime.new method and
DateTime.new is now used to construct a DateTime from a Date, Time and
UTC offset.

DateTime is _not_ a `copy` type as we may need to store additional
non-copy data in the future, such as more detailed timezone related
objects.

This fixes #309.

Changelog: changed
  • Loading branch information
yorickpeterse committed Dec 17, 2024
1 parent 127ae65 commit 586ba69
Show file tree
Hide file tree
Showing 4 changed files with 638 additions and 246 deletions.
20 changes: 19 additions & 1 deletion std/src/std/fs.inko
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class copy Time {
fn to_date_time -> DateTime {
let time = @secs.to_float + (@nanos.to_float / 1_000_000_000.0)

DateTime.from_timestamp(time, utc_offset: 0)
DateTime.from_timestamp(time, utc_offset: 0).get
}
}

Expand Down Expand Up @@ -147,6 +147,12 @@ class pub inline Metadata {
# 1970-01-01 00:00:00), an `Option[DateTime]` is returned. If the creation
# time is available, the value is a `Option.Some(DateTime)`, otherwise it's a
# `None`.
#
# # Panics
#
# This method may panic if the time can't be expressed in a `DateTime`. This
# can only happen if the system clock is returning nonsensical values (e.g. a
# year outside of the 32-bits signed integer range).
fn pub created_at -> Option[DateTime] {
match @created_at {
case Some(v) -> Option.Some(v.to_date_time)
Expand All @@ -157,13 +163,25 @@ class pub inline Metadata {
# Returns the time at which the file was last modified.
#
# This corresponds to the "mtime" field of `stat()` on Unix systems.
#
# # Panics
#
# This method may panic if the time can't be expressed in a `DateTime`. This
# can only happen if the system clock is returning nonsensical values (e.g. a
# year outside of the 32-bits signed integer range).
fn pub modified_at -> DateTime {
@modified_at.to_date_time
}

# Returns the time at which the file was last accessed.
#
# This corresponds to the `atime` field of `stat()` on Unix systems.
#
# # Panics
#
# This method may panic if the time can't be expressed in a `DateTime`. This
# can only happen if the system clock is returning nonsensical values (e.g. a
# year outside of the 32-bits signed integer range).
fn pub accessed_at -> DateTime {
@accessed_at.to_date_time
}
Expand Down
Loading

0 comments on commit 586ba69

Please sign in to comment.