pub struct GameDateTime(pub NaiveDateTime);
Expand description
NewType wrapper for NaiveDateTime
, representing in-game date and time.
§Example
use commonlibsse_ng::re::Calendar::{GameDateTime, Year, MonthIndex, GameDay, Hour};
let year = Year::new(2025.0);
let month = MonthIndex::new(2.0); // March (0-based)
let day = GameDay::new(28.0);
let hour = Hour::new(15.5); // 15:30
let date_time = GameDateTime::new(year, month, day, hour).unwrap();
assert_eq!(date_time.to_string(), "2025-03-28 15:30:00");
Tuple Fields§
§0: NaiveDateTime
Implementations§
Source§impl GameDateTime
impl GameDateTime
Sourcepub const DEFAULT: Self
pub const DEFAULT: Self
The default in-game date: 77-01-01 00:00:00
.
§Example
use commonlibsse_ng::re::Calendar::GameDateTime;
assert_eq!(GameDateTime::default().to_string(), "0077-01-01 00:00:00");
Sourcepub fn new(
year: Year,
month: MonthIndex,
day: GameDay,
hour: Hour,
) -> Option<Self>
pub fn new( year: Year, month: MonthIndex, day: GameDay, hour: Hour, ) -> Option<Self>
Creates a new GameDateTime
from year, month, day, and hour components.
- The month uses 0-based indexing internally (
0 = January
,11 = December
). - The day and hour values are clamped to their valid ranges.
Returns None
if the date or time is invalid.
§Example
use commonlibsse_ng::re::Calendar::{GameDateTime, Year, MonthIndex, GameDay, Hour};
let year = Year::new(2025.0);
let month = MonthIndex::new(2.0); // March
let day = GameDay::new(15.0);
let hour = Hour::new(9.75); // 9:45
let date_time = GameDateTime::new(year, month, day, hour).unwrap();
assert_eq!(date_time.to_string(), "2025-03-15 09:45:00");
// Invalid date returns `None`
let invalid = GameDateTime::new(year, MonthIndex::new(12.0), day, hour);
assert!(invalid.is_none());
Sourcepub const fn from_ymd(year: i32, month: u32, day: u32) -> Self
pub const fn from_ymd(year: i32, month: u32, day: u32) -> Self
Creates a NaiveDateTime
from year, month, and day components.
This is a helper function to avoid using deprecated from_ymd
directly.
§Panics
- Panics if the provided date or time is invalid or out of range.
§Example
use commonlibsse_ng::re::Calendar::GameDateTime;
let date = GameDateTime::from_ymd(2025, 3, 27);
// Panics: invalid date
// let invalid = from_ymd(2025, 13, 32);
Trait Implementations§
Source§impl Clone for GameDateTime
impl Clone for GameDateTime
Source§fn clone(&self) -> GameDateTime
fn clone(&self) -> GameDateTime
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for GameDateTime
impl Debug for GameDateTime
Source§impl Default for GameDateTime
impl Default for GameDateTime
Source§impl Display for GameDateTime
impl Display for GameDateTime
Source§impl Hash for GameDateTime
impl Hash for GameDateTime
Source§impl Ord for GameDateTime
impl Ord for GameDateTime
Source§fn cmp(&self, other: &GameDateTime) -> Ordering
fn cmp(&self, other: &GameDateTime) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for GameDateTime
impl PartialEq for GameDateTime
Source§impl PartialOrd for GameDateTime
impl PartialOrd for GameDateTime
impl Copy for GameDateTime
impl Eq for GameDateTime
impl StructuralPartialEq for GameDateTime
Auto Trait Implementations§
impl Freeze for GameDateTime
impl RefUnwindSafe for GameDateTime
impl Send for GameDateTime
impl Sync for GameDateTime
impl Unpin for GameDateTime
impl UnwindSafe for GameDateTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more