1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use crate::translate::*; |
4 | |
5 | // rustdoc-stripper-ignore-next |
6 | /// A value representing an interval of time, in microseconds. |
7 | #[doc (alias = "GTimeSpan" )] |
8 | #[derive (Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
9 | pub struct TimeSpan(pub i64); |
10 | |
11 | impl FromGlib<i64> for TimeSpan { |
12 | #[inline ] |
13 | unsafe fn from_glib(v: i64) -> TimeSpan { |
14 | TimeSpan(v) |
15 | } |
16 | } |
17 | |
18 | impl IntoGlib for TimeSpan { |
19 | type GlibType = i64; |
20 | |
21 | #[inline ] |
22 | fn into_glib(self) -> i64 { |
23 | self.0 |
24 | } |
25 | } |
26 | |
27 | impl TimeSpan { |
28 | // rustdoc-stripper-ignore-next |
29 | /// Create a new timespan from microseconds. |
30 | pub fn from_microseconds(v: i64) -> TimeSpan { |
31 | TimeSpan(v) |
32 | } |
33 | |
34 | // rustdoc-stripper-ignore-next |
35 | /// Create a new timespan from milliseconds. |
36 | pub fn from_milliseconds(v: i64) -> TimeSpan { |
37 | TimeSpan(v * ffi::G_TIME_SPAN_MILLISECOND) |
38 | } |
39 | |
40 | // rustdoc-stripper-ignore-next |
41 | /// Create a new timespan from seconds. |
42 | pub fn from_seconds(v: i64) -> TimeSpan { |
43 | TimeSpan(v * ffi::G_TIME_SPAN_SECOND) |
44 | } |
45 | |
46 | // rustdoc-stripper-ignore-next |
47 | /// Create a new timespan from minutes. |
48 | pub fn from_minutes(v: i64) -> TimeSpan { |
49 | TimeSpan(v * ffi::G_TIME_SPAN_MINUTE) |
50 | } |
51 | |
52 | // rustdoc-stripper-ignore-next |
53 | /// Create a new timespan from hours. |
54 | pub fn from_hours(v: i64) -> TimeSpan { |
55 | TimeSpan(v * ffi::G_TIME_SPAN_HOUR) |
56 | } |
57 | |
58 | // rustdoc-stripper-ignore-next |
59 | /// Create a new timespan from days. |
60 | pub fn from_days(v: i64) -> TimeSpan { |
61 | TimeSpan(v * ffi::G_TIME_SPAN_DAY) |
62 | } |
63 | |
64 | // rustdoc-stripper-ignore-next |
65 | /// Return the full number of microseconds in this `TimeSpan`. |
66 | pub fn as_microseconds(self) -> i64 { |
67 | self.0 |
68 | } |
69 | |
70 | // rustdoc-stripper-ignore-next |
71 | /// Return the full number of milliseconds in this `TimeSpan`. |
72 | pub fn as_milliseconds(self) -> i64 { |
73 | self.0 / ffi::G_TIME_SPAN_MILLISECOND |
74 | } |
75 | |
76 | // rustdoc-stripper-ignore-next |
77 | /// Return the full number of seconds in this `TimeSpan`. |
78 | pub fn as_seconds(self) -> i64 { |
79 | self.0 / ffi::G_TIME_SPAN_SECOND |
80 | } |
81 | |
82 | // rustdoc-stripper-ignore-next |
83 | /// Return the full number of minutes in this `TimeSpan`. |
84 | pub fn as_minutes(self) -> i64 { |
85 | self.0 / ffi::G_TIME_SPAN_MINUTE |
86 | } |
87 | |
88 | // rustdoc-stripper-ignore-next |
89 | /// Return the full number of hours in this `TimeSpan`. |
90 | pub fn as_hours(self) -> i64 { |
91 | self.0 / ffi::G_TIME_SPAN_HOUR |
92 | } |
93 | |
94 | // rustdoc-stripper-ignore-next |
95 | /// Return the full number of days in this `TimeSpan`. |
96 | pub fn as_days(self) -> i64 { |
97 | self.0 / ffi::G_TIME_SPAN_DAY |
98 | } |
99 | } |
100 | |