Skip to content

Commit 76698f5

Browse files
committed
Merge pull request #1 from barosl/gmtoff-to-utcoff
Rename tm_gmtoff to tm_utcoff
2 parents 8b636c1 + bcbcda5 commit 76698f5

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub struct Tm {
257257
/// Identifies the time zone that was used to compute this broken-down time value, including any
258258
/// adjustment for Daylight Saving Time. This is the number of seconds east of UTC. For example,
259259
/// for U.S. Pacific Daylight Time, the value is -7*60*60 = -25200.
260-
pub tm_gmtoff: i32,
260+
pub tm_utcoff: i32,
261261

262262
/// Nanoseconds after the second - [0, 10<sup>9</sup> - 1]
263263
pub tm_nsec: i32,
@@ -274,7 +274,7 @@ pub fn empty_tm() -> Tm {
274274
tm_wday: 0_i32,
275275
tm_yday: 0_i32,
276276
tm_isdst: 0_i32,
277-
tm_gmtoff: 0_i32,
277+
tm_utcoff: 0_i32,
278278
tm_nsec: 0_i32,
279279
}
280280
}
@@ -313,7 +313,7 @@ impl Tm {
313313
/// Convert time to the seconds from January 1, 1970
314314
pub fn to_timespec(&self) -> Timespec {
315315
unsafe {
316-
let sec = match self.tm_gmtoff {
316+
let sec = match self.tm_utcoff {
317317
0_i32 => rustrt::rust_time_timegm(self),
318318
_ => rustrt::rust_time_mktime(self)
319319
};
@@ -373,7 +373,7 @@ impl Tm {
373373
* utc: "Thu, 22 Mar 2012 14:53:18 GMT"
374374
*/
375375
pub fn rfc822(&self) -> TmFmt {
376-
if self.tm_gmtoff == 0_i32 {
376+
if self.tm_utcoff == 0_i32 {
377377
TmFmt {
378378
tm: self,
379379
format: FmtStr("%a, %d %b %Y %T GMT"),
@@ -744,10 +744,10 @@ impl<'a> fmt::Show for TmFmt<'a> {
744744
'w' => return (tm.tm_wday as int).fmt(fmt),
745745
'Y' => return (tm.tm_year as int + 1900).fmt(fmt),
746746
'y' => return write!(fmt, "{:02d}", (tm.tm_year as int + 1900) % 100),
747-
'Z' => if tm.tm_gmtoff == 0_i32 { "GMT"} else { "" }, // FIXME (#2350): support locale
747+
'Z' => if tm.tm_utcoff == 0_i32 { "UTC"} else { "" }, // FIXME (#2350): support locale
748748
'z' => {
749-
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
750-
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
749+
let sign = if tm.tm_utcoff > 0_i32 { '+' } else { '-' };
750+
let mut m = num::abs(tm.tm_utcoff) / 60_i32;
751751
let h = m / 60_i32;
752752
m -= h * 60_i32;
753753
return write!(fmt, "{}{:02d}{:02d}", sign, h, m);
@@ -778,7 +778,7 @@ impl<'a> fmt::Show for TmFmt<'a> {
778778
self.tm.to_local().asctime().fmt(fmt)
779779
}
780780
FmtRfc3339 => {
781-
if self.tm.tm_gmtoff == 0_i32 {
781+
if self.tm.tm_utcoff == 0_i32 {
782782
TmFmt {
783783
tm: self.tm,
784784
format: FmtStr("%Y-%m-%dT%H:%M:%SZ"),
@@ -788,8 +788,8 @@ impl<'a> fmt::Show for TmFmt<'a> {
788788
tm: self.tm,
789789
format: FmtStr("%Y-%m-%dT%H:%M:%S"),
790790
};
791-
let sign = if self.tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
792-
let mut m = num::abs(self.tm.tm_gmtoff) / 60_i32;
791+
let sign = if self.tm.tm_utcoff > 0_i32 { '+' } else { '-' };
792+
let mut m = num::abs(self.tm.tm_utcoff) / 60_i32;
793793
let h = m / 60_i32;
794794
m -= h * 60_i32;
795795
write!(fmt, "{}{}{:02d}:{:02d}", s, sign, h as int, m as int)
@@ -1150,7 +1150,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
11501150
}
11511151
'Z' => {
11521152
if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") {
1153-
tm.tm_gmtoff = 0_i32;
1153+
tm.tm_utcoff = 0_i32;
11541154
Ok(pos + 3u)
11551155
} else {
11561156
// It's odd, but to maintain compatibility with c's
@@ -1174,7 +1174,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
11741174
Some(item) => {
11751175
let (v, pos) = item;
11761176
if v == 0_i32 {
1177-
tm.tm_gmtoff = 0_i32;
1177+
tm.tm_utcoff = 0_i32;
11781178
}
11791179

11801180
Ok(pos)
@@ -1201,7 +1201,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
12011201
tm_wday: 0_i32,
12021202
tm_yday: 0_i32,
12031203
tm_isdst: 0_i32,
1204-
tm_gmtoff: 0_i32,
1204+
tm_utcoff: 0_i32,
12051205
tm_nsec: 0_i32,
12061206
};
12071207
let mut pos = 0u;
@@ -1247,7 +1247,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ParseError> {
12471247
tm_wday: tm.tm_wday,
12481248
tm_yday: tm.tm_yday,
12491249
tm_isdst: tm.tm_isdst,
1250-
tm_gmtoff: tm.tm_gmtoff,
1250+
tm_utcoff: tm.tm_utcoff,
12511251
tm_nsec: tm.tm_nsec,
12521252
})
12531253
} else { result }
@@ -1349,7 +1349,7 @@ mod tests {
13491349
assert_eq!(utc.tm_wday, 5_i32);
13501350
assert_eq!(utc.tm_yday, 43_i32);
13511351
assert_eq!(utc.tm_isdst, 0_i32);
1352-
assert_eq!(utc.tm_gmtoff, 0_i32);
1352+
assert_eq!(utc.tm_utcoff, 0_i32);
13531353
assert_eq!(utc.tm_nsec, 54321_i32);
13541354
}
13551355

@@ -1370,7 +1370,7 @@ mod tests {
13701370
assert_eq!(local.tm_wday, 5_i32);
13711371
assert_eq!(local.tm_yday, 43_i32);
13721372
assert_eq!(local.tm_isdst, 0_i32);
1373-
assert_eq!(local.tm_gmtoff, -28800_i32);
1373+
assert_eq!(local.tm_utcoff, -28800_i32);
13741374
assert_eq!(local.tm_nsec, 54321_i32);
13751375
}
13761376

@@ -1412,7 +1412,7 @@ mod tests {
14121412
assert!(tm.tm_year == 0_i32);
14131413
assert!(tm.tm_wday == 0_i32);
14141414
assert!(tm.tm_isdst == 0_i32);
1415-
assert!(tm.tm_gmtoff == 0_i32);
1415+
assert!(tm.tm_utcoff == 0_i32);
14161416
assert!(tm.tm_nsec == 0_i32);
14171417
}
14181418
Err(_) => ()
@@ -1435,7 +1435,7 @@ mod tests {
14351435
assert!(tm.tm_wday == 5_i32);
14361436
assert!(tm.tm_yday == 0_i32);
14371437
assert!(tm.tm_isdst == 0_i32);
1438-
assert!(tm.tm_gmtoff == 0_i32);
1438+
assert!(tm.tm_utcoff == 0_i32);
14391439
assert!(tm.tm_nsec == 12340000_i32);
14401440
}
14411441
}
@@ -1549,9 +1549,9 @@ mod tests {
15491549
assert!(test("6", "%w"));
15501550
assert!(test("2009", "%Y"));
15511551
assert!(test("09", "%y"));
1552-
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
1552+
assert!(strptime("-0000", "%z").unwrap().tm_utcoff ==
15531553
0);
1554-
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
1554+
assert!(strptime("-0800", "%z").unwrap().tm_utcoff ==
15551555
0);
15561556
assert!(test("%", "%%"));
15571557

src/time_helpers.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ typedef struct {
6868
int32_t tm_wday;
6969
int32_t tm_yday;
7070
int32_t tm_isdst;
71-
int32_t tm_gmtoff;
71+
int32_t tm_utcoff;
7272
int32_t tm_nsec;
7373
} rust_time_tm;
7474

@@ -87,7 +87,7 @@ static void rust_time_tm_to_tm(rust_time_tm* in_tm, struct tm* out_tm) {
8787

8888
static void tm_to_rust_tm(struct tm* in_tm,
8989
rust_time_tm* out_tm,
90-
int32_t gmtoff,
90+
int32_t utcoff,
9191
int32_t nsec) {
9292
out_tm->tm_sec = in_tm->tm_sec;
9393
out_tm->tm_min = in_tm->tm_min;
@@ -98,7 +98,7 @@ static void tm_to_rust_tm(struct tm* in_tm,
9898
out_tm->tm_wday = in_tm->tm_wday;
9999
out_tm->tm_yday = in_tm->tm_yday;
100100
out_tm->tm_isdst = in_tm->tm_isdst;
101-
out_tm->tm_gmtoff = gmtoff;
101+
out_tm->tm_utcoff = utcoff;
102102
out_tm->tm_nsec = nsec;
103103
}
104104

@@ -151,12 +151,12 @@ rust_time_localtime(int64_t sec, int32_t nsec, rust_time_tm *timeptr) {
151151
LOCALTIME(&s, &tm);
152152

153153
#if defined(__WIN32__)
154-
int32_t gmtoff = -timezone;
154+
int32_t utcoff = -timezone;
155155
#else
156-
int32_t gmtoff = tm.tm_gmtoff;
156+
int32_t utcoff = tm.tm_gmtoff;
157157
#endif
158158

159-
tm_to_rust_tm(&tm, timeptr, gmtoff, nsec);
159+
tm_to_rust_tm(&tm, timeptr, utcoff, nsec);
160160
}
161161

162162
int64_t

0 commit comments

Comments
 (0)