Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider splitting DateTime into a Date and Time type #309

Closed
yorickpeterse opened this issue May 30, 2021 · 4 comments
Closed

Consider splitting DateTime into a Date and Time type #309

yorickpeterse opened this issue May 30, 2021 · 4 comments
Assignees
Labels
feature New things to add to Inko, such as a new standard library module std Changes related to the standard library
Milestone

Comments

@yorickpeterse
Copy link
Collaborator

The type SystemTime, which is being renamed to DateTime as part of https://gitlab.com/inko-lang/inko/-/merge_requests/120, currently stores all its data (years, month, etc) as separate fields. In https://gitlab.com/inko-lang/inko/-/merge_requests/120 I'm also strongly considering removing support for default arguments. This makes constructing a DateTime a bit more tricky when you only want to specify a subset of the data. For example, if you want to create a DateTime for 1980-01-01 00:00:00 you'd have to write this:

DateTime.new(year: 1980, month: 1, day: 1, hour: 0, minute: 0, second: 0, sub_second: 0.0, utc_offset: 0)

Adding all sorts of static methods to this type leads to a clunky API. Instead, the following is much nicer:

let date = Date.new(year: 1980, month: 1, day: 1)
let time = Time.midnight

DateTime.new(date, time)

Another benefit is that we now have dedicated date and time types that only operate on a date or time; instead of both.

@yorickpeterse
Copy link
Collaborator Author

In addition to this split, I think we need support for different time zones, and perhaps TZ DB parsing. This way the VM only needs to support producing timestamps in UTC. That in turn would allow us to work around the time-rs crate not supporting local offsets (time-rs/time#293).

In short, I want the standard library date/time code to be good enough so we don't need third-party libraries like JodaTime in Java.

@yorickpeterse
Copy link
Collaborator Author

chronotope/chrono#677 chrono should now support parsing timezone files without relying on localtime_r.

@yorickpeterse
Copy link
Collaborator Author

The time-rs dependency is removed as part of https://gitlab.com/inko-lang/inko/-/commit/d07e3543a47c6312fc5883dcd9d138329a2e5aa7, and we now just use the underlying libc/Windows APIs directly.

@yorickpeterse
Copy link
Collaborator Author

Two resources worth looking into:

@yorickpeterse yorickpeterse added feature New things to add to Inko, such as a new standard library module and removed type::feature labels Mar 15, 2023
@yorickpeterse yorickpeterse removed this from the 0.2.5 milestone Mar 15, 2023
@yorickpeterse yorickpeterse added this to the 0.18.0 milestone Dec 17, 2024
@yorickpeterse yorickpeterse self-assigned this Dec 17, 2024
yorickpeterse added a commit that referenced this issue Dec 17, 2024
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
yorickpeterse added a commit that referenced this issue Dec 18, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New things to add to Inko, such as a new standard library module std Changes related to the standard library
Projects
None yet
Development

No branches or pull requests

1 participant