Crate easy_time

Crate easy_time 

Source
Expand description

§Easy Time

A simple and intuitive library for handling time in Rust.

easy_time provides a convenient wrapper around chrono to make common time operations more ergonomic and readable. Calculate dates in the future or past with ease using human-friendly static methods.

§Features

  • Simple static API for time calculations (seconds, minutes, hours, days, months, years, etc.)
  • Support for both local time and UTC
  • Generic over any chrono timezone
  • Handles edge cases like leap years and month boundaries
  • Human-readable method names like days_from_now() and months_ago()

§Quick Start

use easy_time::EasyTime;
use chrono::Local;

// Calculate 5 days from now
let future = EasyTime::<Local>::days_from_now(5);

// Calculate 3 months ago
let past = EasyTime::<Local>::months_ago(3);

// Using UTC
let utc_future = EasyTime::<Local>::utc_hours_from_now(10);

Structs§

EasyTime
The main struct for time operations.

Constants§

DATE_FORMAT
Date-only format: YYYY-MM-DD
DEFAULT_DATE_FORMAT
Default date format: YYYY-MM-DD HH:MM:SS
TIME_FORMAT
Time-only format: HH:MM:SS

Functions§

format_datetime
Formats a datetime using the default format: YYYY-MM-DD HH:MM:SS.
format_datetime_with
Formats a datetime using a custom format string.
format_datetime_with_timezone
Formats a datetime with timezone offset appended.
format_datetime_with_timezone_format
Formats a datetime with custom format and timezone offset.
to_date
Returns just the date portion as YYYY-MM-DD.
to_time
Returns just the time portion as HH:MM:SS.
to_timestamp
Returns the Unix timestamp (seconds since epoch).