#date #pretty-print #date-format #date-time #formatting #human-readable #chrono

pretty_date

A rust library for the simple, friendly, human readable formatting of the chrono NaiveDateTime

3 releases

0.1.2 Jan 4, 2023
0.1.1 Jan 3, 2023
0.1.0 Jan 3, 2023

#40 in #date-format

Download history 89/week @ 2024-10-02 31/week @ 2024-10-09 149/week @ 2024-10-16 115/week @ 2024-10-23 57/week @ 2024-10-30 63/week @ 2024-11-06 78/week @ 2024-11-13 43/week @ 2024-11-20 81/week @ 2024-11-27 55/week @ 2024-12-04 40/week @ 2024-12-11 33/week @ 2024-12-18 31/week @ 2024-12-25 84/week @ 2025-01-01 95/week @ 2025-01-08 63/week @ 2025-01-15

273 downloads per month
Used in timeline-service

MIT/Apache

13KB
178 lines

Pretty Date

A rust library for the simple, friendly, human readable formatting for the chrono NaiveDateTime, for example:

  • Within the last ten minutes: Just now
  • Earlier today: 20:56 Today
  • Earlier in the year: 5 September, 23:56

Usage

Add this to your Cargo.toml:

[dependencies]
pretty_date = "0.1.2"

Basic default usage:

use chrono::NaiveDateTime;
use pretty_date::pretty_date_formatter::PrettyDateFormatter;

fn main() {
    let date = NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S").unwrap();
    println!("{}", date.format_pretty());
}

Advanced usage:

use chrono::NaiveDateTime;
use pretty_date::pretty_date_format::PrettyDateFormat;
use pretty_date::pretty_date_rule::PrettyDateRule;

fn main() {
    let date = NaiveDateTime::parse_from_str("2015-09-05 23:56:04", "%Y-%m-%d %H:%M:%S").unwrap();
    let date_format = PrettyDateFormat {
        rules: vec![
            PrettyDateRule::Today,
            PrettyDateRule::ThisYear,
        ],
        default_format: "%-e %B %Y, %H:%M",
    };
    println!("{}", date_format.format_pretty(&date));
}

License

Rand is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.

Dependencies

~1MB
~18K SLoC