#duration #time #helper #extension #tool

duration_helper

Simple std::time::Duration extension methods for i64 and f64 types: 5.hours()

1 unstable release

0.1.0 Aug 14, 2023

#487 in Date and time

MIT license

7KB
85 lines

Duration Extensions

A tiny Rust utility to provide a more concise way to define std::time::Duration

Usage

use duration_helper::DurationHelper;

let half_a_second = 0.5.secs();
let five_hours = 5.hours();
let day_and_a_half = 1.5.days();

Features

  • Extensions for:
    • Nanoseconds: nanos()
    • Microseconds: micros()
    • Milliseconds: millis()
    • Seconds: secs()
    • Hours: hours()
    • Days: days()
    • Weeks: weeks()
    • Months (approximated as 30 days): months()
    • Years (approximated as 365 days): years()

lib.rs:

DurationHelper - A Rust crate to simplify the creation of Duration objects.

This library provides a set of helper methods to easily construct std::time::Duration objects from integers and floating point numbers. By mimicking the naming conventions from std::time::Duration, it aims to provide an intuitive way to create durations.

Examples

use duration_helper::DurationHelper;

let five_seconds = 5.secs();
let two_hours = 2.hours();
let half_a_day = 0.5.days();

Features

  • Convert numbers directly to Duration objects.
  • Intuitive naming aligned with std::time::Duration.
  • Support for a wide range of time units, from nanoseconds to years.
  • Both integer and floating point number types are supported.

Note: This library makes some assumptions, particularly for larger durations. For example, a month is considered as 30 days and a year is considered as 365 days.

No runtime deps