Skip to content

Commit

Permalink
Add DateTime::local_unix_epoch (#4479)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Dec 21, 2023
1 parent 7de8cd4 commit 4d961df
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

- Components
- `icu_calendar`
- New `DateTime::local_unix_epoch()` convenience constructor (https://github.com/unicode-org/icu4x/pull/4479)
- `icu_properties`
- Add `Aran` script code (https://github.com/unicode-org/icu4x/pull/4426)
- Data model and providers
Expand Down
9 changes: 9 additions & 0 deletions components/calendar/src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ impl DateTime<Iso> {
})
}

/// Constructs an ISO datetime representing the UNIX epoch on January 1, 1970
/// at midnight.
pub fn local_unix_epoch() -> Self {
DateTime {
date: Date::unix_epoch(),
time: types::Time::midnight(),
}
}

/// Minute count representation of calendars starting from 00:00:00 on Jan 1st, 1970.
///
/// ```rust
Expand Down
2 changes: 2 additions & 0 deletions ffi/capi/bindings/c/ICU4XIsoDateTime.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ffi/capi/bindings/cpp/ICU4XIsoDateTime.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions ffi/capi/bindings/cpp/ICU4XIsoDateTime.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions ffi/capi/bindings/dart/IsoDateTime.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ffi/capi/bindings/js/ICU4XIsoDateTime.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ffi/capi/bindings/js/ICU4XIsoDateTime.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ffi/capi/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ pub mod ffi {
Box::new(ICU4XIsoDateTime(dt))
}

/// Creates a new [`ICU4XIsoDateTime`] of midnight on January 1, 1970
#[diplomat::rust_link(icu::calendar::DateTime::local_unix_epoch, FnInStruct)]
pub fn local_unix_epoch() -> Box<ICU4XIsoDateTime> {
let dt = DateTime::local_unix_epoch();
Box::new(ICU4XIsoDateTime(dt))
}

/// Construct from the minutes since the local unix epoch for this date (Jan 1 1970, 00:00)
#[diplomat::rust_link(
icu::calendar::DateTime::from_minutes_since_local_unix_epoch,
Expand Down

0 comments on commit 4d961df

Please sign in to comment.