1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use *;
/*
pub fn ago(timestamp1: i64, timestamp2: i64) -> String {
let diff = timestamp2 - timestamp1;
let dt = Utc.timestamp(timestamp1, 0);
let duration = Duration::seconds(diff);
let mut elapsed_time = duration.whole_minutes();
if elapsed_time < 60 { return format!("{:?}m ago", elapsed_time) }; // example: 2m ago
elapsed_time = duration.whole_hours();
if elapsed_time < 24 { return format!("{:?}h ago", elapsed_time) }; // example: 4h ago
elapsed_time = duration.whole_days();
if elapsed_time < 2 { return format!("yesterday") }; // example: yesterday
if elapsed_time < 7 { return format!("{:?}", dt.weekday()) }; // example: Thu
if elapsed_time < 365 { return dt.format("%d %b").to_string() }; // example: 25 Jan
dt.format("%d %b %Y").to_string() // example: 25 Jan 2020
}
*/