#chrono #date-time #persian #jalali

chrono-persian

simple wrapper around chrono for persian(jalali) dates

2 releases

0.1.1 Nov 9, 2024
0.1.0 Nov 9, 2024

#196 in Date and time

Download history 19/week @ 2024-11-03 197/week @ 2024-11-10 8/week @ 2024-11-17

224 downloads per month

MIT license

8KB
68 lines

chrono-persian

c d

About

this crate contains a set of helper functions to convert chrono datetimes to persian (jalali) calender it provides a simple Trait ToPersian which is implemented for NaiveDateTime, DateTime<Utc> and DateTime<Local

Example

use chrono::{DateTime, Utc, Local, NaiveDateTime};
use chrono_persian::ToPersian;
 
// convert a datetime utc
let utc = "2024-11-09 22:38:28 UTC".parse::<DateTime<Utc>>().unwrap();
let a = utc.to_persian().unwrap();
assert_eq!(a.to_string(), "1403-08-20 02:08:28 UTC");

//convert a datetime local
let local = "2024-11-10 02:17:54 +03:30".parse::<DateTime<Local>>().unwrap();
let b = local.to_persian().unwrap();
assert_eq!(b.to_string(), "1403-08-20 02:17:54 +00:00");
   
//convert a naivedatetime
let now = NaiveDateTime::parse_from_str("2024-11-09 23:07:00","%Y-%m-%d %H:%M:%S").unwrap();
let a = now.to_persian().unwrap();
assert_eq!(a.to_string(),"1403-08-19 23:07:00");
 

Dependencies

~1MB
~18K SLoC