@@ -207,41 +207,37 @@ pub enum OutputFormat {
207207}
208208
209209struct FormattedUptime {
210- up_days : i64 ,
211- up_hours : i64 ,
212- up_mins : i64 ,
210+ days : i64 ,
211+ hours : i64 ,
212+ mins : i64 ,
213213}
214214
215215impl FormattedUptime {
216- fn new ( up_secs : i64 ) -> Self {
217- let up_days = up_secs / 86400 ;
218- let up_hours = ( up_secs - ( up_days * 86400 ) ) / 3600 ;
219- let up_mins = ( up_secs - ( up_days * 86400 ) - ( up_hours * 3600 ) ) / 60 ;
220-
221- Self {
222- up_days,
223- up_hours,
224- up_mins,
225- }
216+ fn new ( seconds : i64 ) -> Self {
217+ let days = seconds / 86400 ;
218+ let hours = ( seconds - ( days * 86400 ) ) / 3600 ;
219+ let mins = ( seconds - ( days * 86400 ) - ( hours * 3600 ) ) / 60 ;
220+
221+ Self { days, hours, mins }
226222 }
227223
228224 fn get_human_readable_uptime ( & self ) -> String {
229225 translate ! (
230226 "uptime-format" ,
231- "days" => self . up_days ,
232- "time" => format!( "{:02}:{:02}" , self . up_hours , self . up_mins ) )
227+ "days" => self . days ,
228+ "time" => format!( "{:02}:{:02}" , self . hours , self . mins ) )
233229 }
234230
235231 fn get_pretty_print_uptime ( & self ) -> String {
236232 let mut parts = Vec :: new ( ) ;
237- if self . up_days > 0 {
238- parts. push ( translate ! ( "uptime-format-pretty-day" , "day" => self . up_days ) ) ;
233+ if self . days > 0 {
234+ parts. push ( translate ! ( "uptime-format-pretty-day" , "day" => self . days ) ) ;
239235 }
240- if self . up_hours > 0 {
241- parts. push ( translate ! ( "uptime-format-pretty-hour" , "hour" => self . up_hours ) ) ;
236+ if self . hours > 0 {
237+ parts. push ( translate ! ( "uptime-format-pretty-hour" , "hour" => self . hours ) ) ;
242238 }
243- if self . up_mins > 0 || parts. is_empty ( ) {
244- parts. push ( translate ! ( "uptime-format-pretty-min" , "min" => self . up_mins ) ) ;
239+ if self . mins > 0 || parts. is_empty ( ) {
240+ parts. push ( translate ! ( "uptime-format-pretty-min" , "min" => self . mins ) ) ;
245241 }
246242 parts. join ( ", " )
247243 }
@@ -279,13 +275,13 @@ pub fn get_formatted_uptime(
279275 boot_time : Option < time_t > ,
280276 output_format : OutputFormat ,
281277) -> UResult < String > {
282- let up_secs = get_uptime ( boot_time) ?;
278+ let uptime = get_uptime ( boot_time) ?;
283279
284- if up_secs < 0 {
280+ if uptime < 0 {
285281 Err ( UptimeError :: SystemUptime ) ?;
286282 }
287283
288- let formatted_uptime = FormattedUptime :: new ( up_secs ) ;
284+ let formatted_uptime = FormattedUptime :: new ( uptime ) ;
289285
290286 match output_format {
291287 OutputFormat :: HumanReadable => Ok ( formatted_uptime. get_human_readable_uptime ( ) ) ,
0 commit comments