Skip to content

Commit

Permalink
Rename tm_gmtoff to tm_utcoff
Browse files Browse the repository at this point in the history
Rename the tm_gmtoff field of time::Tm to tm_utcoff.

Although GMT and UTC are commonly used interchangeably, UTC is more
appropriate to denote the time standard.

Python, for example, uses datetime.utcoffset() to represent the offset
from UTC.

[breaking-change]
  • Loading branch information
barosl committed Nov 10, 2014
1 parent 830c82d commit 7c64600
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
40 changes: 20 additions & 20 deletions src/libtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub struct Tm {
/// Identifies the time zone that was used to compute this broken-down time value, including any
/// adjustment for Daylight Saving Time. This is the number of seconds east of UTC. For example,
/// for U.S. Pacific Daylight Time, the value is -7*60*60 = -25200.
pub tm_gmtoff: i32,
pub tm_utcoff: i32,

/// Nanoseconds after the second - [0, 10<sup>9</sup> - 1]
pub tm_nsec: i32,
Expand All @@ -284,7 +284,7 @@ pub fn empty_tm() -> Tm {
tm_wday: 0_i32,
tm_yday: 0_i32,
tm_isdst: 0_i32,
tm_gmtoff: 0_i32,
tm_utcoff: 0_i32,
tm_nsec: 0_i32,
}
}
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Tm {
/// Convert time to the seconds from January 1, 1970
pub fn to_timespec(&self) -> Timespec {
unsafe {
let sec = match self.tm_gmtoff {
let sec = match self.tm_utcoff {
0_i32 => rustrt::rust_timegm(self),
_ => rustrt::rust_mktime(self)
};
Expand Down Expand Up @@ -383,7 +383,7 @@ impl Tm {
* utc: "Thu, 22 Mar 2012 14:53:18 GMT"
*/
pub fn rfc822(&self) -> TmFmt {
if self.tm_gmtoff == 0_i32 {
if self.tm_utcoff == 0_i32 {
TmFmt {
tm: self,
format: FmtStr("%a, %d %b %Y %T GMT"),
Expand Down Expand Up @@ -754,10 +754,10 @@ impl<'a> fmt::Show for TmFmt<'a> {
'w' => return (tm.tm_wday as int).fmt(fmt),
'Y' => return (tm.tm_year as int + 1900).fmt(fmt),
'y' => return write!(fmt, "{:02d}", (tm.tm_year as int + 1900) % 100),
'Z' => if tm.tm_gmtoff == 0_i32 { "GMT"} else { "" }, // FIXME (#2350): support locale
'Z' => if tm.tm_utcoff == 0_i32 { "UTC"} else { "" }, // FIXME (#2350): support locale
'z' => {
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
let sign = if tm.tm_utcoff > 0_i32 { '+' } else { '-' };
let mut m = num::abs(tm.tm_utcoff) / 60_i32;
let h = m / 60_i32;
m -= h * 60_i32;
return write!(fmt, "{}{:02d}{:02d}", sign, h, m);
Expand Down Expand Up @@ -788,7 +788,7 @@ impl<'a> fmt::Show for TmFmt<'a> {
self.tm.to_local().asctime().fmt(fmt)
}
FmtRfc3339 => {
if self.tm.tm_gmtoff == 0_i32 {
if self.tm.tm_utcoff == 0_i32 {
TmFmt {
tm: self.tm,
format: FmtStr("%Y-%m-%dT%H:%M:%SZ"),
Expand All @@ -798,8 +798,8 @@ impl<'a> fmt::Show for TmFmt<'a> {
tm: self.tm,
format: FmtStr("%Y-%m-%dT%H:%M:%S"),
};
let sign = if self.tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
let mut m = num::abs(self.tm.tm_gmtoff) / 60_i32;
let sign = if self.tm.tm_utcoff > 0_i32 { '+' } else { '-' };
let mut m = num::abs(self.tm.tm_utcoff) / 60_i32;
let h = m / 60_i32;
m -= h * 60_i32;
write!(fmt, "{}{}{:02d}:{:02d}", s, sign, h as int, m as int)
Expand Down Expand Up @@ -1160,7 +1160,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
}
'Z' => {
if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") {
tm.tm_gmtoff = 0_i32;
tm.tm_utcoff = 0_i32;
Ok(pos + 3u)
} else {
// It's odd, but to maintain compatibility with c's
Expand All @@ -1184,7 +1184,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
Some(item) => {
let (v, pos) = item;
if v == 0_i32 {
tm.tm_gmtoff = 0_i32;
tm.tm_utcoff = 0_i32;
}

Ok(pos)
Expand All @@ -1211,7 +1211,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
tm_wday: 0_i32,
tm_yday: 0_i32,
tm_isdst: 0_i32,
tm_gmtoff: 0_i32,
tm_utcoff: 0_i32,
tm_nsec: 0_i32,
};
let mut pos = 0u;
Expand Down Expand Up @@ -1257,7 +1257,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
tm_wday: tm.tm_wday,
tm_yday: tm.tm_yday,
tm_isdst: tm.tm_isdst,
tm_gmtoff: tm.tm_gmtoff,
tm_utcoff: tm.tm_utcoff,
tm_nsec: tm.tm_nsec,
})
} else { result }
Expand Down Expand Up @@ -1359,7 +1359,7 @@ mod tests {
assert_eq!(utc.tm_wday, 5_i32);
assert_eq!(utc.tm_yday, 43_i32);
assert_eq!(utc.tm_isdst, 0_i32);
assert_eq!(utc.tm_gmtoff, 0_i32);
assert_eq!(utc.tm_utcoff, 0_i32);
assert_eq!(utc.tm_nsec, 54321_i32);
}

Expand All @@ -1380,7 +1380,7 @@ mod tests {
assert_eq!(local.tm_wday, 5_i32);
assert_eq!(local.tm_yday, 43_i32);
assert_eq!(local.tm_isdst, 0_i32);
assert_eq!(local.tm_gmtoff, -28800_i32);
assert_eq!(local.tm_utcoff, -28800_i32);
assert_eq!(local.tm_nsec, 54321_i32);
}

Expand Down Expand Up @@ -1422,7 +1422,7 @@ mod tests {
assert!(tm.tm_year == 0_i32);
assert!(tm.tm_wday == 0_i32);
assert!(tm.tm_isdst == 0_i32);
assert!(tm.tm_gmtoff == 0_i32);
assert!(tm.tm_utcoff == 0_i32);
assert!(tm.tm_nsec == 0_i32);
}
Err(_) => ()
Expand All @@ -1445,7 +1445,7 @@ mod tests {
assert!(tm.tm_wday == 5_i32);
assert!(tm.tm_yday == 0_i32);
assert!(tm.tm_isdst == 0_i32);
assert!(tm.tm_gmtoff == 0_i32);
assert!(tm.tm_utcoff == 0_i32);
assert!(tm.tm_nsec == 12340000_i32);
}
}
Expand Down Expand Up @@ -1559,9 +1559,9 @@ mod tests {
assert!(test("6", "%w"));
assert!(test("2009", "%Y"));
assert!(test("09", "%y"));
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
assert!(strptime("-0000", "%z").unwrap().tm_utcoff ==
0);
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
assert!(strptime("-0800", "%z").unwrap().tm_utcoff ==
0);
assert!(test("%", "%%"));

Expand Down
12 changes: 6 additions & 6 deletions src/rt/rust_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ typedef struct {
int32_t tm_wday;
int32_t tm_yday;
int32_t tm_isdst;
int32_t tm_gmtoff;
int32_t tm_utcoff;
int32_t tm_nsec;
} rust_tm;

Expand All @@ -129,7 +129,7 @@ void rust_tm_to_tm(rust_tm* in_tm, struct tm* out_tm) {

void tm_to_rust_tm(struct tm* in_tm,
rust_tm* out_tm,
int32_t gmtoff,
int32_t utcoff,
int32_t nsec) {
out_tm->tm_sec = in_tm->tm_sec;
out_tm->tm_min = in_tm->tm_min;
Expand All @@ -140,7 +140,7 @@ void tm_to_rust_tm(struct tm* in_tm,
out_tm->tm_wday = in_tm->tm_wday;
out_tm->tm_yday = in_tm->tm_yday;
out_tm->tm_isdst = in_tm->tm_isdst;
out_tm->tm_gmtoff = gmtoff;
out_tm->tm_utcoff = utcoff;
out_tm->tm_nsec = nsec;
}

Expand Down Expand Up @@ -193,12 +193,12 @@ rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
LOCALTIME(&s, &tm);

#if defined(__WIN32__)
int32_t gmtoff = -timezone;
int32_t utcoff = -timezone;
#else
int32_t gmtoff = tm.tm_gmtoff;
int32_t utcoff = tm.tm_utcoff;
#endif

tm_to_rust_tm(&tm, timeptr, gmtoff, nsec);
tm_to_rust_tm(&tm, timeptr, utcoff, nsec);
}

int64_t
Expand Down

0 comments on commit 7c64600

Please sign in to comment.