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
333
334
335
336
337
338
339
340
341
342
343
344
use ;
use ;
/// ### local_now()
///
/// Retrieves the current local time based on a variable timezone offset.
///
/// This function returns the current local system time as a `SystemTime` object,
/// adjusted from the current UTC time by a timezone offset obtained from a function.
/// This allows for dynamic adjustments based on different timezone settings, which may
/// be particularly useful for applications that need to handle multiple timezones,
/// including daylight saving changes.
///
/// ### Example
///
/// ```
/// use wtime::local::local_now;
///
/// let now = local_now();
/// println!("Current local time: {:?}", now);
/// ```
///
/// ### Panics
///
/// This function does not panic under normal circumstances; however, it may panic
/// if there is an issue with the system clock, such as if the current time is before
/// the Unix epoch (January 1, 1970). It may also panic if the conversion to a
/// `Duration` fails due to time going backwards or an invalid timezone offset.
///
/// ### Note
///
/// The timezone offset is obtained dynamically via the `tz_number()` function,
/// allowing for more flexibility than a hard-coded offset. Ensure that `tz_number()`
/// accurately reflects the intended timezone offset in hours. Calculating the offset
/// in seconds allows for precise adjustment of the UTC time to the local time.
///
/// <small>End Fun Doc</small>
/// ### local_ts_sec()
///
/// Retrieves the current local time as a UNIX timestamp in seconds.
///
/// This function calculates the local time in seconds since the UNIX epoch by
/// adding the local timezone offset (in hours) to the current UTC timestamp.
/// This is useful for obtaining a UNIX timestamp that reflects the local time
/// settings.
///
/// ### Example
///
/// ```
/// use wtime::local::local_ts_sec;
///
/// let local_timestamp = local_ts_sec();
/// println!("Current Local Timestamp in Seconds: {}", local_timestamp);
/// ```
///
/// ### Returns
///
/// Returns the current local time as a `u64` representing the number of seconds
/// since the UNIX epoch.
///
/// <small>End Fun Doc</small>
/// ### local_ts_millis()
///
/// Retrieves the current local time as a UNIX timestamp in milliseconds.
///
/// This function calculates the local time in milliseconds since the UNIX epoch
/// by adding the local timezone offset (in hours) to the current UTC timestamp.
/// This is useful for obtaining a timestamp that is precise to the millisecond for
/// applications that require high-resolution timing.
///
/// ### Example
///
/// ```
/// use wtime::local::local_ts_millis;
///
/// let local_timestamp_millis = local_ts_millis();
/// println!("Current Local Timestamp in Milliseconds: {}", local_timestamp_millis);
/// ```
///
/// ### Returns
///
/// Returns the current local time as a `u128` representing the number of milliseconds
/// since the UNIX epoch.
///
/// <small>End Fun Doc</small>
/// ### local_ts_nanos()
///
/// Retrieves the current local time as a UNIX timestamp in nanoseconds.
///
/// This function calculates the local time in nanoseconds since the UNIX epoch
/// by adding the local timezone offset (in hours) to the current UTC timestamp.
/// This is useful for applications that require extremely high-resolution timestamps.
///
/// ### Example
///
/// ```
/// use wtime::local::local_ts_nanos;
///
/// let local_timestamp_nanos = local_ts_nanos();
/// println!("Current Local Timestamp in Nanoseconds: {}", local_timestamp_nanos);
/// ```
///
/// ### Returns
///
/// Returns the current local time as a `u128` representing the number of nanoseconds
/// since the UNIX epoch.
///
/// <small>End Fun Doc</small>
/// ### get_local_year() -> u64
///
/// Retrieves the current year.
///
/// This function calculates the current year based on the current local timestamp.
///
/// ### Example
///
/// ```
/// use wtime::local::get_local_year;
///
/// let year = get_local_year();
/// println!("Current year: {}", year);
/// ```
///
/// ### Returns
///
/// Returns the current year as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_local_month() -> u64
///
/// Retrieves the current month.
///
/// This function calculates the current month based on the current local timestamp.
///
/// ### Example
///
/// ```
/// use wtime::local::get_local_month;
///
/// let month = get_local_month();
/// println!("Current month: {}", month);
/// ```
///
/// ### Returns
///
/// Returns the current month as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_local_day() -> u64
///
/// Retrieves the current day of the month.
///
/// This function calculates the current day based on the current local timestamp.
///
/// ### Example
///
/// ```
/// use wtime::local::get_local_day;
///
/// let day = get_local_day();
/// println!("Current day: {}", day);
/// ```
///
/// ### Returns
///
/// Returns the current day of the month as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### get_local_hour() -> u64
///
/// Retrieves the current hour of the day.
///
/// This function calculates the current hour based on the current local timestamp.
/// The hour is returned in 24-hour format (0-23).
///
/// ### Example
///
/// ```
/// use wtime::local::get_local_hour;
///
/// let hour = get_local_hour();
/// println!("Current hour: {}", hour);
/// ```
///
/// ### Returns
///
/// Returns the current hour of the day as a `u64`.
///
/// <small>End Fun Doc</small>
/// ### format_local_ts()
///
/// Retrieves the current local 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::local::format_local_ts;
///
/// let timestamp = format_local_ts();
///
/// // Simulate generating a unique ID with a suffix
/// let unique_id_with_suffix = format!("ID-{}-{}", format_local_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::local::format_local_ts;
///
/// let timestamp = format_local_ts();
///
/// // Simulate generating a unique ID without a suffix
/// let unique_id_without_suffix = format!("ID-{}", format_local_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 local 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::local::format_local_ts;
///
/// let blog_post_timestamp = format!("BlogPost Timestamp: {}", format_local_ts());
/// println!("Generated Blog Post Local Timestamp: {}", blog_post_timestamp);
/// ```
///
/// ### Example
///
/// ```rust
/// use wtime::local::format_local_ts;
///
/// let timestamp = format_local_ts();
/// println!("Formatted Local Timestamp: {}", timestamp);
/// ```
///
/// ### Returns
///
/// Returns a `String` representing the current local 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>