Skip to content

Commit 86e54fb

Browse files
committed
libtime: Remove the tz_zone field from times.
It depends on `~str`.
1 parent 6067106 commit 86e54fb

File tree

2 files changed

+7
-71
lines changed

2 files changed

+7
-71
lines changed

src/libtime/lib.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,11 @@ pub struct Tm {
237237
/// for U.S. Pacific Daylight Time, the value is -7*60*60 = -25200.
238238
pub tm_gmtoff: i32,
239239

240-
/// Abbreviated name for the time zone that was used to compute this broken-down time value.
241-
/// For example, U.S. Pacific Daylight Time is "PDT".
242-
pub tm_zone: ~str,
243-
244240
/// Nanoseconds after the second – [0, 10<sup>9</sup> - 1]
245241
pub tm_nsec: i32,
246242
}
247243

248244
pub fn empty_tm() -> Tm {
249-
// 64 is the max size of the timezone buffer allocated on windows
250-
// in rust_localtime. In glibc the max timezone size is supposedly 3.
251-
let mut zone = StrBuf::new();
252-
for _ in range(0, 64) {
253-
zone.push_char(' ')
254-
}
255245
Tm {
256246
tm_sec: 0_i32,
257247
tm_min: 0_i32,
@@ -263,7 +253,6 @@ pub fn empty_tm() -> Tm {
263253
tm_yday: 0_i32,
264254
tm_isdst: 0_i32,
265255
tm_gmtoff: 0_i32,
266-
tm_zone: zone.into_owned(),
267256
tm_nsec: 0_i32,
268257
}
269258
}
@@ -745,7 +734,6 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, StrBuf> {
745734
'Z' => {
746735
if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") {
747736
tm.tm_gmtoff = 0_i32;
748-
tm.tm_zone = "UTC".to_owned();
749737
Ok(pos + 3u)
750738
} else {
751739
// It's odd, but to maintain compatibility with c's
@@ -770,7 +758,6 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, StrBuf> {
770758
let (v, pos) = item;
771759
if v == 0_i32 {
772760
tm.tm_gmtoff = 0_i32;
773-
tm.tm_zone = "UTC".to_owned();
774761
}
775762

776763
Ok(pos)
@@ -801,7 +788,6 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, StrBuf> {
801788
tm_yday: 0_i32,
802789
tm_isdst: 0_i32,
803790
tm_gmtoff: 0_i32,
804-
tm_zone: "".to_owned(),
805791
tm_nsec: 0_i32,
806792
};
807793
let mut pos = 0u;
@@ -848,7 +834,6 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, StrBuf> {
848834
tm_yday: tm.tm_yday,
849835
tm_isdst: tm.tm_isdst,
850836
tm_gmtoff: tm.tm_gmtoff,
851-
tm_zone: tm.tm_zone.clone(),
852837
tm_nsec: tm.tm_nsec,
853838
})
854839
} else { result }
@@ -1050,7 +1035,7 @@ pub fn strftime(format: &str, tm: &Tm) -> StrBuf {
10501035
'w' => (tm.tm_wday as int).to_str().to_strbuf(),
10511036
'Y' => (tm.tm_year as int + 1900).to_str().to_strbuf(),
10521037
'y' => format_strbuf!("{:02d}", (tm.tm_year as int + 1900) % 100),
1053-
'Z' => tm.tm_zone.to_strbuf(),
1038+
'Z' => "".to_strbuf(), // FIXME(pcwalton): Implement this.
10541039
'z' => {
10551040
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
10561041
let mut m = num::abs(tm.tm_gmtoff) / 60_i32;
@@ -1176,7 +1161,6 @@ mod tests {
11761161
assert_eq!(utc.tm_yday, 43_i32);
11771162
assert_eq!(utc.tm_isdst, 0_i32);
11781163
assert_eq!(utc.tm_gmtoff, 0_i32);
1179-
assert_eq!(utc.tm_zone, "UTC".to_owned());
11801164
assert_eq!(utc.tm_nsec, 54321_i32);
11811165
}
11821166

@@ -1198,12 +1182,6 @@ mod tests {
11981182
assert_eq!(local.tm_yday, 43_i32);
11991183
assert_eq!(local.tm_isdst, 0_i32);
12001184
assert_eq!(local.tm_gmtoff, -28800_i32);
1201-
1202-
// FIXME (#2350): We should probably standardize on the timezone
1203-
// abbreviation.
1204-
let zone = &local.tm_zone;
1205-
assert!(*zone == "PST".to_owned() || *zone == "Pacific Standard Time".to_owned());
1206-
12071185
assert_eq!(local.tm_nsec, 54321_i32);
12081186
}
12091187

@@ -1246,7 +1224,6 @@ mod tests {
12461224
assert!(tm.tm_wday == 0_i32);
12471225
assert!(tm.tm_isdst == 0_i32);
12481226
assert!(tm.tm_gmtoff == 0_i32);
1249-
assert!(tm.tm_zone == "".to_owned());
12501227
assert!(tm.tm_nsec == 0_i32);
12511228
}
12521229
Err(_) => ()
@@ -1270,7 +1247,6 @@ mod tests {
12701247
assert!(tm.tm_yday == 0_i32);
12711248
assert!(tm.tm_isdst == 0_i32);
12721249
assert!(tm.tm_gmtoff == 0_i32);
1273-
assert!(tm.tm_zone == "".to_owned());
12741250
assert!(tm.tm_nsec == 12340000_i32);
12751251
}
12761252
}
@@ -1382,10 +1358,6 @@ mod tests {
13821358
assert!(test("6", "%w"));
13831359
assert!(test("2009", "%Y"));
13841360
assert!(test("09", "%y"));
1385-
assert!(strptime("UTC", "%Z").unwrap().tm_zone ==
1386-
"UTC".to_owned());
1387-
assert!(strptime("PST", "%Z").unwrap().tm_zone ==
1388-
"".to_owned());
13891361
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
13901362
0);
13911363
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
@@ -1457,12 +1429,6 @@ mod tests {
14571429
assert_eq!(local.strftime("%Y"), "2009".to_strbuf());
14581430
assert_eq!(local.strftime("%y"), "09".to_strbuf());
14591431
assert_eq!(local.strftime("%+"), "2009-02-13T15:31:30-08:00".to_strbuf());
1460-
1461-
// FIXME (#2350): We should probably standardize on the timezone
1462-
// abbreviation.
1463-
let zone = local.strftime("%Z");
1464-
assert!(zone == "PST".to_strbuf() || zone == "Pacific Standard Time".to_strbuf());
1465-
14661432
assert_eq!(local.strftime("%z"), "-0800".to_strbuf());
14671433
assert_eq!(local.strftime("%%"), "%".to_strbuf());
14681434

src/rt/rust_builtin.c

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,6 @@ rust_list_dir_wfd_fp_buf(void* wfd) {
127127
}
128128
#endif
129129

130-
typedef struct
131-
{
132-
size_t fill; // in bytes; if zero, heapified
133-
size_t alloc; // in bytes
134-
uint8_t data[0];
135-
} rust_vec;
136-
137-
typedef rust_vec rust_str;
138-
139130
typedef struct {
140131
int32_t tm_sec;
141132
int32_t tm_min;
@@ -147,7 +138,6 @@ typedef struct {
147138
int32_t tm_yday;
148139
int32_t tm_isdst;
149140
int32_t tm_gmtoff;
150-
rust_str *tm_zone;
151141
int32_t tm_nsec;
152142
} rust_tm;
153143

@@ -164,8 +154,10 @@ void rust_tm_to_tm(rust_tm* in_tm, struct tm* out_tm) {
164154
out_tm->tm_isdst = in_tm->tm_isdst;
165155
}
166156

167-
void tm_to_rust_tm(struct tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
168-
const char *zone, int32_t nsec) {
157+
void tm_to_rust_tm(struct tm* in_tm,
158+
rust_tm* out_tm,
159+
int32_t gmtoff,
160+
int32_t nsec) {
169161
out_tm->tm_sec = in_tm->tm_sec;
170162
out_tm->tm_min = in_tm->tm_min;
171163
out_tm->tm_hour = in_tm->tm_hour;
@@ -177,13 +169,6 @@ void tm_to_rust_tm(struct tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
177169
out_tm->tm_isdst = in_tm->tm_isdst;
178170
out_tm->tm_gmtoff = gmtoff;
179171
out_tm->tm_nsec = nsec;
180-
181-
if (zone != NULL) {
182-
size_t size = strlen(zone);
183-
assert(out_tm->tm_zone->alloc >= size);
184-
memcpy(out_tm->tm_zone->data, zone, size);
185-
out_tm->tm_zone->fill = size;
186-
}
187172
}
188173

189174
#if defined(__WIN32__)
@@ -225,7 +210,7 @@ rust_gmtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
225210
time_t s = sec;
226211
GMTIME(&s, &tm);
227212

228-
tm_to_rust_tm(&tm, timeptr, 0, "UTC", nsec);
213+
tm_to_rust_tm(&tm, timeptr, 0, nsec);
229214
}
230215

231216
void
@@ -234,28 +219,13 @@ rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
234219
time_t s = sec;
235220
LOCALTIME(&s, &tm);
236221

237-
const char* zone = NULL;
238222
#if defined(__WIN32__)
239223
int32_t gmtoff = -timezone;
240-
wchar_t wbuffer[64] = {0};
241-
char buffer[256] = {0};
242-
// strftime("%Z") can contain non-UTF-8 characters on non-English locale (issue #9418),
243-
// so time zone should be converted from UTF-16 string.
244-
// Since wcsftime depends on setlocale() result,
245-
// instead we convert it using MultiByteToWideChar.
246-
if (strftime(buffer, sizeof(buffer) / sizeof(char), "%Z", &tm) > 0) {
247-
// ANSI -> UTF-16
248-
MultiByteToWideChar(CP_ACP, 0, buffer, -1, wbuffer, sizeof(wbuffer) / sizeof(wchar_t));
249-
// UTF-16 -> UTF-8
250-
WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, sizeof(buffer), NULL, NULL);
251-
zone = buffer;
252-
}
253224
#else
254225
int32_t gmtoff = tm.tm_gmtoff;
255-
zone = tm.tm_zone;
256226
#endif
257227

258-
tm_to_rust_tm(&tm, timeptr, gmtoff, zone, nsec);
228+
tm_to_rust_tm(&tm, timeptr, gmtoff, nsec);
259229
}
260230

261231
int64_t

0 commit comments

Comments
 (0)