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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
use ;
use SystemTime;
/// ### utc_now()
///
/// Retrieves the current UTC time as a `SystemTime`.
///
/// This function returns the current system time in Coordinated Universal Time (UTC)
/// as a `SystemTime` object. It can be used for logging events, measuring elapsed time,
/// or in any other situation where the current time in UTC is required.
///
/// ### Example
///
/// ```
/// use wtime::utc::utc_now;
///
/// let now = utc_now();
/// println!("Current UTC time: {:?}", now);
/// ```
///
/// ### Panics
///
/// This function does not panic, but it's important to note that when converting the
/// returned `SystemTime` to another time representation, such as a DateTime, it may fail
/// if the system time is unrepresentable.
///
/// ### Note
///
/// The return value is based on the system's current clock and may be affected by system
/// time changes, such as adjustments from network time protocols.
///
/// <small>End Fun Doc</small>
/// ### utc_ts_sec()
///
/// Retrieves the current UTC time as a UNIX timestamp.
///
/// This function calculates the number of seconds that have elapsed since the UNIX epoch
/// (January 1, 1970) and returns it as a `u64`. This can be useful for applications
/// that need to store or transmit timestamps in a standardized format.
///
/// ### Example
///
/// ```
/// use wtime::utc::utc_ts_sec;
///
/// let current_timestamp = utc_ts_sec();
/// println!("Current UTC Timestamp in Seconds: {}", current_timestamp);
/// ```
///
/// ### Returns
///
/// Returns the current time as a `u64` representing the number of seconds since the UNIX epoch.
///
/// ### Panics
///
/// This function does not panic, but if it were to be called in an environment where
/// system time is not available or has gone backward, it could yield incorrect results.
///
/// <small>End Fun Doc</small>
/// ### utc_ts_millis()
///
/// Retrieves the current UTC time as a UNIX timestamp.
///
/// This function calculates the number of milli-seconds that have elapsed since the UNIX epoch
/// (January 1, 1970) and returns it as a `u128`. This can be useful for applications
/// that need to store or transmit timestamps in a standardized format.
///
/// ### Example
///
/// ```
/// use wtime::utc::utc_ts_millis;
///
/// let current_timestamp = utc_ts_millis();
/// println!("Current UTC Timestamp in Milli-seconds: {}", current_timestamp);
/// ```
///
/// ### Returns
///
/// Returns the current time as a `u128` representing the number of seconds since the UNIX epoch.
///
/// ### Panics
///
/// This function does not panic, but if it were to be called in an environment where
/// system time is not available or has gone backward, it could yield incorrect results.
///
/// <small>End Fun Doc</small>
/// ### utc_ts_nanos()
///
/// Retrieves the current UTC time as a UNIX timestamp.
///
/// This function calculates the number of nano-seconds that have elapsed since the UNIX epoch
/// (January 1, 1970) and returns it as a `u128`. This can be useful for applications
/// that need to store or transmit timestamps in a standardized format.
///
/// ### Example
///
/// ```
/// use wtime::utc::utc_ts_nanos;
///
/// let current_timestamp = utc_ts_nanos();
/// println!("Current UTC Timestamp in Nano-seconds: {}", current_timestamp);
/// ```
///
/// ### Returns
///
/// Returns the current time as a `u128` representing the number of seconds since the UNIX epoch.
///
/// ### Panics
///
/// This function does not panic, but if it were to be called in an environment where
/// system time is not available or has gone backward, it could yield incorrect results.
///
/// <small>End Fun Doc</small>
/// ### get_year() -> u64
///
/// Retrieves the current year.
///
/// This function calculates the current year based on the current UTC timestamp.
///
/// ### Example
///
/// ```
/// use wtime::utc::get_year;
///
/// let year = get_year();
/// println!("Current year: {}", year);
/// ```
///
/// ### Returns
///
/// Returns the current year as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_month() -> u64
///
/// Retrieves the current month.
///
/// This function calculates the current month based on the current UTC timestamp.
///
/// ### Example
///
/// ```
/// use wtime::utc::get_month;
///
/// let month = get_month();
/// println!("Current month: {}", month);
/// ```
///
/// ### Returns
///
/// Returns the current month as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_day() -> u64
///
/// Retrieves the current day of the month.
///
/// This function calculates the current day based on the current UTC timestamp.
///
/// ### Example
///
/// ```
/// use wtime::utc::get_day;
///
/// let day = get_day();
/// println!("Current day: {}", day);
/// ```
///
/// ### Returns
///
/// Returns the current day of the month as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_hour() -> u64
///
/// Retrieves the current hour of the day.
///
/// This function calculates the current hour based on the current UTC timestamp.
/// The hour is returned in 24-hour format (0-23).
///
/// ### Example
///
/// ```
/// use wtime::utc::get_hour;
///
/// let hour = get_hour();
/// println!("Current hour: {}", hour);
/// ```
///
/// ### Returns
///
/// Returns the current hour of the day as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### format_utc_ts()
///
/// Retrieves the current UTC timestamp formatted as a string.
///
/// This function generates a formatted timestamp string in the structure
/// `year-month-day-hour-minute-second-millis-nanos`, adhering to the
/// following specifications for each component:
/// - Year: 4 digits (e.g., `2024`)
/// - Month: 2 digits, zero-padded (01-12)
/// - Day: 2 digits, zero-padded (01-31)
/// - Hour: 2 digits, zero-padded (00-23)
/// - Minute: 2 digits, zero-padded (00-59)
/// - Second: 2 digits, zero-padded (00-59)
/// - Milliseconds: 3 digits, zero-padded (000-999)
/// - Nanoseconds: 6 digits, zero-padded (000000-999999)
///
/// This function does not perform error handling or validation beyond the necessary
/// calculations for the timestamp components. It is assumed that the underlying
/// time retrieval functions are functioning correctly and return valid values.
///
/// ### Usage for Creating Unique Identifiers (IDs)
///
/// The formatted timestamp generated by this function can be used as part of unique
/// identifiers (IDs). You can create a timestamp-based ID that is likely to be unique
/// within your application's context, either by combining it with a unique suffix or
/// using it by itself.
///
/// Here's an example using a unique suffix:
/// ```rust
/// use wtime::utc::format_utc_ts;
///
/// let timestamp = format_utc_ts();
///
/// // Simulate generating a unique ID with a suffix
/// let unique_id_with_suffix = format!("ID-{}-{}", format_utc_ts(), "random_suffix"); // Replace with actual random suffix function
/// println!("Generated Unique ID with Suffix: {}", unique_id_with_suffix);
/// ```
///
/// And here's an example using the timestamp by itself:
/// ```rust
/// use wtime::utc::format_utc_ts;
///
/// let timestamp = format_utc_ts();
///
/// // Simulate generating a unique ID without a suffix
/// let unique_id_without_suffix = format!("ID-{}", format_utc_ts());
/// println!("Generated Unique ID without Suffix: {}", unique_id_without_suffix);
/// ```
///
/// ### Usage in Blog Posts
///
/// You can also use the formatted timestamp for logging or identifying blog posts.
/// By generating a unique UTC timestamp string for each blog post, you ensure that
/// there is a clear and systematic way to track each post's creation time.
///
/// Example:
/// ```rust
/// use wtime::utc::format_utc_ts;
///
/// let blog_post_timestamp = format!("BlogPost Timestamp: {}", format_utc_ts());
/// println!("Generated Blog Post UTC Timestamp: {}", blog_post_timestamp);
/// ```
///
/// ### Example
///
/// ```rust
/// use wtime::utc::format_utc_ts;
///
/// let timestamp = format_utc_ts();
/// println!("Formatted UTC Timestamp: {}", timestamp);
/// ```
///
/// ### Returns
///
/// Returns a `String` representing the current UTC timestamp formatted in the specified
/// manner. The length of the returned string is guaranteed to be 30 characters if all
/// components are valid.
///
/// ### Note
///
/// - Ensure that any dependencies or underlying functionality that this function relies
/// upon (such as time retrieval functions) are functioning correctly to avoid unexpected
/// results. No panic conditions are raised in this function; any potential issues should
/// be managed by the developer as appropriate for their use case.
///
/// <small>End Fun Doc</small>