Skip to content

Commit ebeef99

Browse files
drinkcatdjc
authored andcommitted
TimeZone::from_posix_tz: Treat empty TZ variable as UTC
This is not technically POSIX, but glibc and musl behave that way: e.g. `TZ= date` returns a UTC date.
1 parent dc068f0 commit ebeef99

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/offset/local/tz_info/timezone.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ impl TimeZone {
3737

3838
/// Construct a time zone from a POSIX TZ string, as described in [the POSIX documentation of the `TZ` environment variable](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html).
3939
fn from_posix_tz(tz_string: &str) -> Result<Self, Error> {
40+
// It is commonly agreed (but not standard) that setting an empty `TZ=` uses UTC.
4041
if tz_string.is_empty() {
41-
return Err(Error::InvalidTzString("empty TZ string"));
42+
return Ok(Self::utc());
4243
}
4344

4445
if tz_string == "localtime" {
@@ -925,7 +926,7 @@ mod tests {
925926
}
926927

927928
assert!(TimeZone::from_posix_tz("EST5EDT,0/0,J365/25").is_err());
928-
assert!(TimeZone::from_posix_tz("").is_err());
929+
assert_eq!(TimeZone::from_posix_tz("").unwrap().find_local_time_type(0)?.offset(), 0);
929930

930931
Ok(())
931932
}

0 commit comments

Comments
 (0)