1- use rostra_core:: Timestamp ;
21use std:: time:: { SystemTime , UNIX_EPOCH } ;
32
3+ use rostra_core:: Timestamp ;
4+
45pub fn format_timestamp ( timestamp : Timestamp ) -> String {
56 let system_time: SystemTime = UNIX_EPOCH + std:: time:: Duration :: from_secs ( timestamp. 0 ) ;
67 let now = SystemTime :: now ( ) ;
78 let duration_since = now. duration_since ( system_time) . unwrap_or_default ( ) ;
8-
9+
910 let seconds = duration_since. as_secs ( ) ;
10-
11+
1112 if seconds < 60 {
12- format ! ( "{}s" , seconds )
13+ format ! ( "{seconds }s" )
1314 } else if seconds < 3600 {
1415 format ! ( "{}m" , seconds / 60 )
1516 } else if seconds < 86400 {
1617 format ! ( "{}h" , seconds / 3600 )
17- } else if seconds < 2592000 { // 30 days
18+ } else if seconds < 2592000 {
19+ // 30 days
1820 format ! ( "{}d" , seconds / 86400 )
1921 } else {
2022 // For older posts, show the actual date
2123 let timestamp_secs = system_time
2224 . duration_since ( UNIX_EPOCH )
2325 . unwrap_or_default ( )
2426 . as_secs ( ) ;
25-
27+
2628 // Simple date formatting (would be better with chrono crate)
2729 let days_since_epoch = timestamp_secs / 86400 ;
2830 let year = 1970 + days_since_epoch / 365 ;
2931 let day_of_year = days_since_epoch % 365 ;
3032 let month = day_of_year / 30 + 1 ;
3133 let day = day_of_year % 30 + 1 ;
32-
33- format ! ( "{}/{}/{}" , month , day , year )
34+
35+ format ! ( "{month }/{day }/{year}" )
3436 }
35- }
37+ }
0 commit comments