Skip to content

Commit 79355d3

Browse files
nekevssManishearth
andauthored
General updates to temporal_rs's exports and docs (#575)
This PR adds some documentation to some of the modules and `sys` exports. It also removes DateDuration from being a top level export opting instead to export it from a new `duration` module. It also doc hides some of the constants. --------- Co-authored-by: Manish Goregaokar <[email protected]>
1 parent eef688a commit 79355d3

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src/builtins/compiled/duration/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::{
2+
duration::DateDuration,
23
options::{
34
OffsetDisambiguation, RelativeTo, RoundingIncrement, RoundingMode, RoundingOptions, Unit,
45
},
56
partial::PartialDuration,
6-
Calendar, DateDuration, PlainDate, TimeZone, ZonedDateTime,
7+
Calendar, PlainDate, TimeZone, ZonedDateTime,
78
};
89

910
use core::{num::NonZeroU32, str::FromStr};

src/builtins/core/plain_time.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
//! This module implements `Time` and any directly related algorithms.
22
33
use crate::{
4-
builtins::{core::Duration, duration::normalized::InternalDurationRecord},
4+
builtins::{
5+
core::{DateDuration, Duration},
6+
duration::normalized::InternalDurationRecord,
7+
},
58
iso::IsoTime,
69
options::{
710
DifferenceOperation, DifferenceSettings, Overflow, ResolvedRoundingOptions,
811
RoundingOptions, ToStringRoundingOptions, Unit, UnitGroup,
912
},
1013
parsers::{parse_time, IxdtfStringBuilder},
11-
DateDuration, TemporalError, TemporalResult,
14+
TemporalError, TemporalResult,
1215
};
1316
use alloc::string::String;
1417
use core::str::FromStr;

src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ pub use error::TemporalError;
309309
pub use sys::Temporal;
310310

311311
pub mod partial {
312-
//! Partial Date/Time component records.
312+
//! Partial date and time component records
313313
//!
314314
//! The partial records are `temporal_rs`'s method of addressing
315315
//! `TemporalFields` in the specification.
@@ -322,27 +322,33 @@ pub mod partial {
322322
pub mod parsed_intermediates;
323323

324324
// TODO: Potentially bikeshed how `EpochNanoseconds` should be exported.
325+
/// A module for structs related to the UNIX epoch
325326
pub mod unix_time {
326327
pub use timezone_provider::epoch_nanoseconds::EpochNanoseconds;
327328
}
328329

329-
/// The `Now` module includes type for building a Now.
330+
/// The `Now` module includes type for building a Now
330331
pub mod now {
331332
pub use crate::builtins::Now;
332333
}
333334

334-
/// This module exports all of the field types.
335+
/// Duration related types
336+
pub mod duration {
337+
pub use crate::builtins::DateDuration;
338+
}
339+
340+
/// Calendar field records
335341
pub mod fields {
336342
pub use crate::builtins::{
337343
calendar::{CalendarFields, YearMonthCalendarFields},
338344
DateTimeFields, ZonedDateTimeFields,
339345
};
340346
}
341347

348+
// TODO: Should we be exporting MonthCode and UtcOffset here.
342349
pub use crate::builtins::{
343350
calendar::{Calendar, MonthCode},
344351
core::timezone::{TimeZone, UtcOffset},
345-
core::DateDuration,
346352
Duration, Instant, PlainDate, PlainDateTime, PlainMonthDay, PlainTime, PlainYearMonth,
347353
ZonedDateTime,
348354
};
@@ -428,15 +434,19 @@ impl Sign {
428434
}
429435

430436
// Relevant numeric constants
437+
431438
/// Nanoseconds per day constant: 8.64e+13
439+
#[doc(hidden)]
432440
pub const NS_PER_DAY: u64 = MS_PER_DAY as u64 * 1_000_000;
441+
#[doc(hidden)]
433442
pub const NS_PER_DAY_NONZERO: core::num::NonZeroU128 =
434443
if let Some(nz) = core::num::NonZeroU128::new(NS_PER_DAY as u128) {
435444
nz
436445
} else {
437446
unreachable!()
438447
};
439448
/// Milliseconds per day constant: 8.64e+7
449+
#[doc(hidden)]
440450
pub const MS_PER_DAY: u32 = 24 * 60 * 60 * 1000;
441451
/// Max Instant nanosecond constant
442452
#[doc(hidden)]

src/sys.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ use web_time::{SystemTime, UNIX_EPOCH};
2121
// pub struct Temporal(SystemTime<DefaultSystemClock, DefaultSystemTimeZone>)
2222
//
2323

24+
/// The Temporal object for accessing current system time
2425
#[cfg(feature = "sys")]
2526
pub struct Temporal;
2627

2728
#[cfg(feature = "sys")]
2829
impl Temporal {
30+
/// Get a `Now` object for the default host system.
2931
pub fn now() -> Now<DefaultHostSystem> {
3032
Now::new(DefaultHostSystem)
3133
}
3234
}
3335

36+
/// A default host system implementation
37+
///
38+
/// This implementation is backed by [`SystemTime`] and [`iana_time_zone`]
3439
#[cfg(feature = "sys")]
3540
pub struct DefaultHostSystem;
3641

temporal_capi/src/duration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod ffi {
2121

2222
#[diplomat::opaque]
2323
#[diplomat::transparent_convert]
24-
pub struct DateDuration(pub(crate) temporal_rs::DateDuration);
24+
pub struct DateDuration(pub(crate) temporal_rs::duration::DateDuration);
2525

2626
pub struct PartialDuration {
2727
pub years: DiplomatOption<i64>,
@@ -58,7 +58,7 @@ pub mod ffi {
5858
weeks: i64,
5959
days: i64,
6060
) -> Result<Box<Self>, TemporalError> {
61-
temporal_rs::DateDuration::new(years, months, weeks, days)
61+
temporal_rs::duration::DateDuration::new(years, months, weeks, days)
6262
.map(|x| Box::new(DateDuration(x)))
6363
.map_err(Into::into)
6464
}

0 commit comments

Comments
 (0)