Crates.io | wtime |
lib.rs | wtime |
version | 0.6.0 |
source | src |
created_at | 2024-10-14 12:43:54.413319 |
updated_at | 2024-11-05 02:40:21.781282 |
description | WTIME provides a variety of functions for obtaining the current UTC and local times, as well as generating customizable timestamps to suit your needs. |
homepage | https://github.com/dr-montasir/wtime |
repository | https://github.com/dr-montasir/wtime |
max_upload_size | |
id | 1408267 |
size | 46,724 |
WTIME provides a variety of functions for obtaining the current UTC and local times, as well as generating customizable timestamps to suit your needs.
Run the following Cargo command in your project directory:
cargo add wtime
Or add wtime
to your Cargo.toml
file:
[dependencies]
wtime = "MAJOR.MINOR.PATCH" # Replace with the latest version
use wtime::calc::{calc_date, calc_week, get_day_name};
use wtime::utc::get_day;
fn main() {
let (year, month, day) = calc_date(1728933069);
println!("Date: {}-{}-{}", year, month, day); // Date: 2024-10-14
let week_number = calc_week((2024, 10, 14));
println!("Week number: {}", week_number); // 42
let day = get_day();
let day_name = get_day_name(1_670_000_000);
println!("Day name: {}", day_name); // Day name: Friday
println!("Day name: {}", get_day_name(day));
}
use wtime::local::{format_local_ts, local_ts_nanos};
use wtime::utc::utc_ts_nanos;
fn main() {
let local_timestamp_nanos = local_ts_nanos();
println!("Current Local Timestamp in Nanoseconds: {}", local_timestamp_nanos);
let utc_timestamp_nanos = utc_ts_nanos();
println!("Current UTC Timestamp in Nanoseconds: {}", utc_timestamp_nanos);
let timestamp = format_local_ts();
println!("Formatted Local Timestamp: {}", timestamp);
}
use wtime::tz::{tz_number, tz_string};
fn main() {
let offset_number = tz_number();
println!("Current timezone offset in hours: {}", offset_number);
let offset_string = tz_string();
println!("Current timezone offset: {}", offset_string);
}
use wtime::utc::{format_utc_ts, get_day};
fn main() {
let day = get_day();
println!("Current day: {}", day);
let timestamp = format_utc_ts();
println!("Formatted UTC Timestamp: {}", timestamp);
// 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);
// 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);
// Simulate generating a blog post UTC timestamp
let blog_post_timestamp = format!("BlogPost Timestamp: {}", format_utc_ts());
println!("Generated Blog Post UTC Timestamp: {}", blog_post_timestamp);
}
Function | Function | Function |
---|---|---|
calc_date | calc_week | duration_since |
get_day_name | get_millis | get_minute |
get_month_name | get_nanos | get_second |
- | is_leap_year | - |
Function | Function | Function |
---|---|---|
format_local_ts | get_local_day | get_local_hour |
get_local_month | get_local_year | local_now |
local_ts_millis | local_ts_nanos | local_ts_sec |
Function | Function |
---|---|
tz_number | tz_string |
Function | Function | Function |
---|---|---|
format_utc_ts | get_day | get_hour |
get_month | get_year | utc_now |
utc_ts_millis | utc_ts_nanos | utc_ts_sec |
This project is licensed under either of the following licenses:
You may choose either license for your purposes.
Contributions are welcome! Please feel free to submit a pull request or open an issue for any feature requests or bug reports.