Crates.io | timekit |
lib.rs | timekit |
version | 0.2.0 |
source | src |
created_at | 2024-10-10 16:15:00.995338 |
updated_at | 2024-11-30 15:58:16.243104 |
description | A simple Rust library for working with timezones and displaying current time in multiple zones. |
homepage | https://statpan.com |
repository | https://github.com/StatPan/timekit |
max_upload_size | |
id | 1403968 |
size | 43,930 |
TimeKit
is a simple and lightweight Rust library for working with timezones and displaying the current date and time in multiple time zones. This library is designed to be easy to use and efficient, providing hardcoded timezone offsets to avoid runtime computation and enhance performance.
The purpose of TimeKit
is to offer a flexible and convenient way to work with different time zones in Rust, allowing developers to retrieve and display the current time in a variety of world time zones. This project was built to address the need for a lightweight timezone-handling library without external dependencies, focusing on simplicity and usability.
In the globalized world we live in, applications often need to support users in different regions. Having a reliable and efficient method to calculate time across multiple time zones is essential for many systems, including scheduling applications, communication tools, and data logging systems.
TimeDelta
.TimeDelta
(e.g., add or subtract days, hours, minutes, or seconds).YYYY-MM-DD HH:MM:SS
format.To start using TimeKit
, add the following line to your Cargo.toml
file under [dependencies]
:
[dependencies]
timekit = "0.2.0"
Then, in your Rust code:
use timekit;
Here's a simple example showing how to use TimeKit to get the current time in various time zones.
use timekit::TimeZone;
use timekit::now;
fn main() {
// Get the current time in UTC
let utc_time = now(TimeZone::UTC).unwrap();
println!("Current UTC time: {}", utc_time);
// Get the current time in Korea Standard Time (KST)
let kst_time = now(TimeZone::KST).unwrap();
println!("Current KST time: {}", kst_time);
// Get the current time in Eastern Standard Time (EST)
let est_time = now(TimeZone::EST).unwrap();
println!("Current EST time: {}", est_time);
}
You can perform time arithmetic such as adding or subtracting time using the TimeDelta
struct.
use timekit::{DateTime, TimeDelta, TimeZone};
fn main() {
let datetime = DateTime::new(2023, 8, 1, 12, 0, 0, TimeZone::UTC).unwrap();
// Add 1 day and 3 hours to the datetime
let new_datetime = datetime + TimeDelta {
days: 1,
hours: 3,
..Default::default()
};
println!("New DateTime after addition: {}", new_datetime.unwrap());
// Subtract 2 days and 6 hours from the datetime
let earlier_datetime = datetime - TimeDelta {
days: 2,
hours: 6,
..Default::default()
};
println!("New DateTime after subtraction: {}", earlier_datetime.unwrap());
}
TimeKit supports a wide variety of time zones. Here are some of the supported zones:
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to submit a pull request or create an issue in the repository.
This project is licensed under the MIT License. See the LICENSE
file for more details.