Skip to content

Commit 7c64600

Browse files
committed
Rename tm_gmtoff to tm_utcoff
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]
1 parent 830c82d commit 7c64600

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/libtime/lib.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub struct Tm {
267267
/// Identifies the time zone that was used to compute this broken-down time value, including any
268268
/// adjustment for Daylight Saving Time. This is the number of seconds east of UTC. For example,
269269
/// for U.S. Pacific Daylight Time, the value is -7*60*60 = -25200.
270-
pub tm_gmtoff: i32,
270+
pub tm_utcoff: i32,
271271

272272
/// Nanoseconds after the second - [0, 10<sup>9</sup> - 1]
273273
pub tm_nsec: i32,
@@ -284,7 +284,7 @@ pub fn empty_tm() -> Tm {
284284
tm_wday: 0_i32,
285285
tm_yday: 0_i32,
286286
tm_isdst: 0_i32,
287-
tm_gmtoff: 0_i32,
287+
tm_utcoff: 0_i32,
288288
tm_nsec: 0_i32,
289289
}
290290
}
@@ -323,7 +323,7 @@ impl Tm {
323323
/// Convert time to the seconds from January 1, 1970
324324
pub fn to_timespec(&self) -> Timespec {
325325
unsafe {
326-
let sec = match self.tm_gmtoff {
326+
let sec = match self.tm_utcoff {
327327
0_i32 => rustrt::rust_timegm(self),
328328
_ => rustrt::rust_mktime(self)
329329
};
@@ -383,7 +383,7 @@ impl Tm {
383383
* utc: "Thu, 22 Mar 2012 14:53:18 GMT"
384384
*/
385385
pub fn rfc822(&self) -> TmFmt {
386-
if self.tm_gmtoff == 0_i32 {
386+
if self.tm_utcoff == 0_i32 {
387387
TmFmt {
388388
tm: self,
389389
format: FmtStr("%a, %d %b %Y %T GMT"),
@@ -754,10 +754,10 @@ impl<'a> fmt::Show for TmFmt<'a> {
754754
'w' => return (tm.tm_wday as int).fmt(fmt),
755755
'Y' => return (tm.tm_year as int + 1900).fmt(fmt),
756756
'y' => return write!(fmt, "{:02d}", (tm.tm_year as int + 1900) % 100),
757-
'Z' => if tm.tm_gmtoff == 0_i32 { "GMT"} else { "" }, // FIXME (#2350): support locale
757+
'Z' => if tm.tm_utcoff == 0_i32 { "UTC"} else { "" }, // FIXME (#2350): support locale
758758
'z' => {
759-
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
760-
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
759+
let sign = if tm.tm_utcoff > 0_i32 { '+' } else { '-' };
760+
let mut m = num::abs(tm.tm_utcoff) / 60_i32;
761761
let h = m / 60_i32;
762762
m -= h * 60_i32;
763763
return write!(fmt, "{}{:02d}{:02d}", sign, h, m);
@@ -788,7 +788,7 @@ impl<'a> fmt::Show for TmFmt<'a> {
788788
self.tm.to_local().asctime().fmt(fmt)
789789
}
790790
FmtRfc3339 => {
791-
if self.tm.tm_gmtoff == 0_i32 {
791+
if self.tm.tm_utcoff == 0_i32 {
792792
TmFmt {
793793
tm: self.tm,
794794
format: FmtStr("%Y-%m-%dT%H:%M:%SZ"),
@@ -798,8 +798,8 @@ impl<'a> fmt::Show for TmFmt<'a> {
798798
tm: self.tm,
799799
format: FmtStr("%Y-%m-%dT%H:%M:%S"),
800800
};
801-
let sign = if self.tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
802-
let mut m = num::abs(self.tm.tm_gmtoff) / 60_i32;
801+
let sign = if self.tm.tm_utcoff > 0_i32 { '+' } else { '-' };
802+
let mut m = num::abs(self.tm.tm_utcoff) / 60_i32;
803803
let h = m / 60_i32;
804804
m -= h * 60_i32;
805805
write!(fmt, "{}{}{:02d}:{:02d}", s, sign, h as int, m as int)
@@ -1160,7 +1160,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
11601160
}
11611161
'Z' => {
11621162
if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") {
1163-
tm.tm_gmtoff = 0_i32;
1163+
tm.tm_utcoff = 0_i32;
11641164
Ok(pos + 3u)
11651165
} else {
11661166
// It's odd, but to maintain compatibility with c's
@@ -1184,7 +1184,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
11841184
Some(item) => {
11851185
let (v, pos) = item;
11861186
if v == 0_i32 {
1187-
tm.tm_gmtoff = 0_i32;
1187+
tm.tm_utcoff = 0_i32;
11881188
}
11891189

11901190
Ok(pos)
@@ -1211,7 +1211,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
12111211
tm_wday: 0_i32,
12121212
tm_yday: 0_i32,
12131213
tm_isdst: 0_i32,
1214-
tm_gmtoff: 0_i32,
1214+
tm_utcoff: 0_i32,
12151215
tm_nsec: 0_i32,
12161216
};
12171217
let mut pos = 0u;
@@ -1257,7 +1257,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
12571257
tm_wday: tm.tm_wday,
12581258
tm_yday: tm.tm_yday,
12591259
tm_isdst: tm.tm_isdst,
1260-
tm_gmtoff: tm.tm_gmtoff,
1260+
tm_utcoff: tm.tm_utcoff,
12611261
tm_nsec: tm.tm_nsec,
12621262
})
12631263
} else { result }
@@ -1359,7 +1359,7 @@ mod tests {
13591359
assert_eq!(utc.tm_wday, 5_i32);
13601360
assert_eq!(utc.tm_yday, 43_i32);
13611361
assert_eq!(utc.tm_isdst, 0_i32);
1362-
assert_eq!(utc.tm_gmtoff, 0_i32);
1362+
assert_eq!(utc.tm_utcoff, 0_i32);
13631363
assert_eq!(utc.tm_nsec, 54321_i32);
13641364
}
13651365

@@ -1380,7 +1380,7 @@ mod tests {
13801380
assert_eq!(local.tm_wday, 5_i32);
13811381
assert_eq!(local.tm_yday, 43_i32);
13821382
assert_eq!(local.tm_isdst, 0_i32);
1383-
assert_eq!(local.tm_gmtoff, -28800_i32);
1383+
assert_eq!(local.tm_utcoff, -28800_i32);
13841384
assert_eq!(local.tm_nsec, 54321_i32);
13851385
}
13861386

@@ -1422,7 +1422,7 @@ mod tests {
14221422
assert!(tm.tm_year == 0_i32);
14231423
assert!(tm.tm_wday == 0_i32);
14241424
assert!(tm.tm_isdst == 0_i32);
1425-
assert!(tm.tm_gmtoff == 0_i32);
1425+
assert!(tm.tm_utcoff == 0_i32);
14261426
assert!(tm.tm_nsec == 0_i32);
14271427
}
14281428
Err(_) => ()
@@ -1445,7 +1445,7 @@ mod tests {
14451445
assert!(tm.tm_wday == 5_i32);
14461446
assert!(tm.tm_yday == 0_i32);
14471447
assert!(tm.tm_isdst == 0_i32);
1448-
assert!(tm.tm_gmtoff == 0_i32);
1448+
assert!(tm.tm_utcoff == 0_i32);
14491449
assert!(tm.tm_nsec == 12340000_i32);
14501450
}
14511451
}
@@ -1559,9 +1559,9 @@ mod tests {
15591559
assert!(test("6", "%w"));
15601560
assert!(test("2009", "%Y"));
15611561
assert!(test("09", "%y"));
1562-
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
1562+
assert!(strptime("-0000", "%z").unwrap().tm_utcoff ==
15631563
0);
1564-
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
1564+
assert!(strptime("-0800", "%z").unwrap().tm_utcoff ==
15651565
0);
15661566
assert!(test("%", "%%"));
15671567

src/rt/rust_builtin.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef struct {
110110
int32_t tm_wday;
111111
int32_t tm_yday;
112112
int32_t tm_isdst;
113-
int32_t tm_gmtoff;
113+
int32_t tm_utcoff;
114114
int32_t tm_nsec;
115115
} rust_tm;
116116

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

130130
void tm_to_rust_tm(struct tm* in_tm,
131131
rust_tm* out_tm,
132-
int32_t gmtoff,
132+
int32_t utcoff,
133133
int32_t nsec) {
134134
out_tm->tm_sec = in_tm->tm_sec;
135135
out_tm->tm_min = in_tm->tm_min;
@@ -140,7 +140,7 @@ void tm_to_rust_tm(struct tm* in_tm,
140140
out_tm->tm_wday = in_tm->tm_wday;
141141
out_tm->tm_yday = in_tm->tm_yday;
142142
out_tm->tm_isdst = in_tm->tm_isdst;
143-
out_tm->tm_gmtoff = gmtoff;
143+
out_tm->tm_utcoff = utcoff;
144144
out_tm->tm_nsec = nsec;
145145
}
146146

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

195195
#if defined(__WIN32__)
196-
int32_t gmtoff = -timezone;
196+
int32_t utcoff = -timezone;
197197
#else
198-
int32_t gmtoff = tm.tm_gmtoff;
198+
int32_t utcoff = tm.tm_utcoff;
199199
#endif
200200

201-
tm_to_rust_tm(&tm, timeptr, gmtoff, nsec);
201+
tm_to_rust_tm(&tm, timeptr, utcoff, nsec);
202202
}
203203

204204
int64_t

0 commit comments

Comments
 (0)