@@ -83,7 +83,6 @@ use datetime::fmt::DateFormat;
83
83
use datetime:: { LocalDateTime , DatePiece } ;
84
84
use datetime:: TimeZone ;
85
85
use zoneinfo_compiled:: { CompiledData , Result as TZResult } ;
86
- use zoneinfo_data:: ZoneinfoData ;
87
86
88
87
use locale;
89
88
@@ -157,41 +156,32 @@ pub struct Environment<U: Users+Groups> {
157
156
158
157
/// The computer's current time zone. This gets used to determine how to
159
158
/// offset files' timestamps.
160
- tz : TimeZone ,
159
+ tz : Option < TimeZone > ,
161
160
162
161
/// Mapping cache of user IDs to usernames.
163
162
users : Mutex < U > ,
164
163
}
165
164
166
165
impl Default for Environment < UsersCache > {
167
166
fn default ( ) -> Self {
168
- use std :: process :: exit ;
167
+ let tz = determine_time_zone ( ) ;
169
168
170
- let tz = match determine_time_zone ( ) {
171
- Ok ( tz) => tz,
172
- Err ( e) => {
173
- println ! ( "Unable to determine time zone: {}" , e) ;
174
- exit ( 1 ) ;
175
- } ,
176
- } ;
169
+ if let Err ( ref e) = tz {
170
+ println ! ( "Unable to determine time zone: {}" , e) ;
171
+ }
177
172
178
173
Environment {
179
174
current_year : LocalDateTime :: now ( ) . year ( ) ,
180
175
numeric : locale:: Numeric :: load_user_locale ( ) . unwrap_or_else ( |_| locale:: Numeric :: english ( ) ) ,
181
176
time : locale:: Time :: load_user_locale ( ) . unwrap_or_else ( |_| locale:: Time :: english ( ) ) ,
182
- tz : tz,
177
+ tz : tz. ok ( ) ,
183
178
users : Mutex :: new ( UsersCache :: new ( ) ) ,
184
179
}
185
180
}
186
181
}
187
182
188
183
fn determine_time_zone ( ) -> TZResult < TimeZone > {
189
- if let Some ( system_zone) = TimeZone :: system ( ) {
190
- Ok ( system_zone)
191
- }
192
- else {
193
- TimeZone :: from_file ( "/etc/localtime" )
194
- }
184
+ TimeZone :: from_file ( "/etc/localtime" )
195
185
}
196
186
197
187
impl Details {
@@ -597,16 +587,34 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
597
587
598
588
#[ allow( trivial_numeric_casts) ]
599
589
fn render_time ( & self , timestamp : f:: Time ) -> TextCell {
600
- let date = self . env . tz . to_zoned ( LocalDateTime :: at ( timestamp. 0 as i64 ) ) ;
590
+ // TODO(ogham): This method needs some serious de-duping!
591
+ // zoned and local times have different types at the moment,
592
+ // so it's tricky.
593
+
594
+ if let Some ( ref tz) = self . env . tz {
595
+ let date = tz. to_zoned ( LocalDateTime :: at ( timestamp. 0 as i64 ) ) ;
601
596
602
- let datestamp = if date. year ( ) == self . env . current_year {
597
+ let datestamp = if date. year ( ) == self . env . current_year {
603
598
DATE_AND_TIME . format ( & date, & self . env . time )
604
599
}
605
600
else {
606
601
DATE_AND_YEAR . format ( & date, & self . env . time )
607
602
} ;
608
603
609
- TextCell :: paint ( self . opts . colours . date , datestamp)
604
+ TextCell :: paint ( self . opts . colours . date , datestamp)
605
+ }
606
+ else {
607
+ let date = LocalDateTime :: at ( timestamp. 0 as i64 ) ;
608
+
609
+ let datestamp = if date. year ( ) == self . env . current_year {
610
+ DATE_AND_TIME . format ( & date, & self . env . time )
611
+ }
612
+ else {
613
+ DATE_AND_YEAR . format ( & date, & self . env . time )
614
+ } ;
615
+
616
+ TextCell :: paint ( self . opts . colours . date , datestamp)
617
+ }
610
618
}
611
619
612
620
fn render_git_status ( & self , git : f:: Git ) -> TextCell {
@@ -750,16 +758,14 @@ pub mod test {
750
758
impl Default for Environment < MockUsers > {
751
759
fn default ( ) -> Self {
752
760
use locale;
753
- use datetime:: TimeZone ;
754
- use zoneinfo_data:: ZoneinfoData ;
755
761
use users:: mock:: MockUsers ;
756
762
use std:: sync:: Mutex ;
757
763
758
764
Environment {
759
765
current_year : 1234 ,
760
766
numeric : locale:: Numeric :: english ( ) ,
761
767
time : locale:: Time :: english ( ) ,
762
- tz : TimeZone :: get ( "Europe/London" ) . unwrap ( ) ,
768
+ tz : None ,
763
769
users : Mutex :: new ( MockUsers :: with_current_uid ( 0 ) ) ,
764
770
}
765
771
}
0 commit comments