Skip to content

Commit

Permalink
Remove localtime_r and all callsights
Browse files Browse the repository at this point in the history
  • Loading branch information
kflansburg committed Oct 18, 2021
1 parent 4235bd8 commit 6f908cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a> fmt::Display for TmFmt<'a> {

Ok(())
}
Fmt::Ctime => self.tm.to_local().asctime().fmt(fmt),
// Fmt::Ctime => self.tm.to_local().asctime().fmt(fmt),
Fmt::Rfc3339 => {
if self.tm.tm_utcoff == 0 {
TmFmt {
Expand Down
60 changes: 30 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,19 @@ pub fn now_utc() -> Tm {
at_utc(get_time())
}

/// Returns the specified time in the local timezone
pub fn at(clock: Timespec) -> Tm {
let Timespec { sec, nsec } = clock;
let mut tm = empty_tm();
sys::time_to_local_tm(sec, &mut tm);
tm.tm_nsec = nsec;
tm
}

/// Returns the current time in the local timezone
pub fn now() -> Tm {
at(get_time())
}
// /// Returns the specified time in the local timezone
// pub fn at(clock: Timespec) -> Tm {
// let Timespec { sec, nsec } = clock;
// let mut tm = empty_tm();
// sys::time_to_local_tm(sec, &mut tm);
// tm.tm_nsec = nsec;
// tm
// }

// /// Returns the current time in the local timezone
// pub fn now() -> Tm {
// at(get_time())
// }

impl Tm {
/// Convert time to the seconds from January 1, 1970
Expand All @@ -440,10 +440,10 @@ impl Tm {
Timespec::new(sec, self.tm_nsec)
}

/// Convert time to the local timezone
pub fn to_local(&self) -> Tm {
at(self.to_timespec())
}
// /// Convert time to the local timezone
// pub fn to_local(&self) -> Tm {
// at(self.to_timespec())
// }

/// Convert time to the UTC
pub fn to_utc(&self) -> Tm {
Expand All @@ -453,18 +453,18 @@ impl Tm {
}
}

/**
* Returns a TmFmt that outputs according to the `asctime` format in ISO
* C, in the local timezone.
*
* Example: "Thu Jan 1 00:00:00 1970"
*/
pub fn ctime(&self) -> TmFmt {
TmFmt {
tm: self,
format: Fmt::Ctime,
}
}
// /**
// * Returns a TmFmt that outputs according to the `asctime` format in ISO
// * C, in the local timezone.
// *
// * Example: "Thu Jan 1 00:00:00 1970"
// */
// pub fn ctime(&self) -> TmFmt {
// TmFmt {
// tm: self,
// format: Fmt::Ctime,
// }
// }

/**
* Returns a TmFmt that outputs according to the `asctime` format in ISO
Expand Down Expand Up @@ -600,7 +600,7 @@ pub struct TmFmt<'a> {
enum Fmt<'a> {
Str(&'a str),
Rfc3339,
Ctime,
// Ctime,
}

fn validate_format<'a>(fmt: TmFmt<'a>) -> Result<TmFmt<'a>, ParseError> {
Expand Down
50 changes: 25 additions & 25 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,31 +368,31 @@ mod inner {
}
}

pub fn time_to_local_tm(sec: i64, tm: &mut Tm) {
unsafe {
let sec = sec as time_t;
let mut out = mem::zeroed();
if libc::localtime_r(&sec, &mut out).is_null() {
panic!("localtime_r failed: {}", io::Error::last_os_error());
}
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
let gmtoff = {
::tzset();
// < 0 means we don't know; assume we're not in DST.
if out.tm_isdst == 0 {
// timezone is seconds west of UTC, tm_gmtoff is seconds east
-timezone
} else if out.tm_isdst > 0 {
-altzone
} else {
-timezone
}
};
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
let gmtoff = out.tm_gmtoff;
tm_to_rust_tm(&out, gmtoff as i32, tm);
}
}
// pub fn time_to_local_tm(sec: i64, tm: &mut Tm) {
// unsafe {
// let sec = sec as time_t;
// let mut out = mem::zeroed();
// if libc::localtime_r(&sec, &mut out).is_null() {
// panic!("localtime_r failed: {}", io::Error::last_os_error());
// }
// #[cfg(any(target_os = "solaris", target_os = "illumos"))]
// let gmtoff = {
// ::tzset();
// // < 0 means we don't know; assume we're not in DST.
// if out.tm_isdst == 0 {
// // timezone is seconds west of UTC, tm_gmtoff is seconds east
// -timezone
// } else if out.tm_isdst > 0 {
// -altzone
// } else {
// -timezone
// }
// };
// #[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
// let gmtoff = out.tm_gmtoff;
// tm_to_rust_tm(&out, gmtoff as i32, tm);
// }
// }

pub fn utc_tm_to_time(rust_tm: &Tm) -> i64 {
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
Expand Down

0 comments on commit 6f908cb

Please sign in to comment.