Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaa110/rust-persian-calendar
The implementation of the Persian (Solar Hijri) Calendar in Rust
https://github.com/yaa110/rust-persian-calendar
persian-calendar rust rust-crate
Last synced: 3 months ago
JSON representation
The implementation of the Persian (Solar Hijri) Calendar in Rust
- Host: GitHub
- URL: https://github.com/yaa110/rust-persian-calendar
- Owner: yaa110
- License: mit
- Created: 2017-01-21T10:43:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-23T13:38:55.000Z (about 1 year ago)
- Last Synced: 2024-10-08T21:04:35.763Z (3 months ago)
- Topics: persian-calendar, rust, rust-crate
- Language: Rust
- Homepage: https://crates.io/crates/ptime
- Size: 12.7 KB
- Stars: 29
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - yaa110/rust-persian-calendar - ci.org/yaa110/rust-persian-calendar.svg?branch=master">](https://travis-ci.org/yaa110/rust-persian-calendar) (Libraries / Date and time)
- awesome-rust - yaa110/rust-persian-calendar - ci.org/yaa110/rust-persian-calendar.svg?branch=master">](https://travis-ci.org/yaa110/rust-persian-calendar) (Libraries / Date and time)
- awesome-persian - rust-persian-calendar - The implementation of the Persian (Solar Hijri) Calendar in Rust. (Jalali Date)
- awesome-rust-zh - yaa110/rust-persian-calendar - [<img src="https://api.travis-ci.org/yaa110/rust-persian-calendar.svg?branch=master">](https://travis-ci.org/yaa110/rust-persian-calendar) (库 / 日期和时间)
- awesome-rust - yaa110/rust-persian-calendar - ci.org/yaa110/rust-persian-calendar.svg?branch=master">](https://travis-ci.org/yaa110/rust-persian-calendar) (库 Libraries / 日期和时间 Date and time)
README
Rust Persian Calendar
=====================[![crates.io](https://img.shields.io/crates/v/ptime.svg)](https://crates.io/crates/ptime) [![Documentation](https://img.shields.io/badge/Docs-ptime-blue.svg)](https://docs.rs/ptime/0.1.1/ptime) [![Build Status](https://travis-ci.org/yaa110/rust-persian-calendar.svg)](https://travis-ci.org/yaa110/rust-persian-calendar) [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/yaa110/rust-persian-calendar/blob/master/LICENSE)
**Rust Persian Calendar v0.1.1** provides functionality for conversion among Persian (Solar Hijri) and Gregorian calendars. A Julian calendar is used as an interface for all conversions. The crate name is `ptime` and it is compatible with the crate [time](https://crates.io/crates/time). This source code is licensed under MIT license that can be found in the LICENSE file.
## Installation
Add `ptime = "0.1"` to `dependencies` section of `Cargo.toml`:```toml
[dependencies]
time = "0.1"
ptime = "0.1"
```## Getting started
1- Import the crate `ptime`. Most of the time you need to import `time` crate, too.```rust
extern crate ptime;
extern crate time;
```2- Convert Gregorian calendar to Persian calendar.
```rust
let p_tm = ptime::from_gregorian_date(2016, 2, 21).unwrap();assert_eq!(p_tm.tm_year, 1395);
assert_eq!(p_tm.tm_mon, 0);
assert_eq!(p_tm.tm_mday, 2);
```3- Convert Persian calendar to Gregorian calendar.
```rust
let g_tm = ptime::from_persian_date(1395, 0, 2).unwrap().to_gregorian();assert_eq!(g_tm.tm_year, 2016);
assert_eq!(g_tm.tm_mon, 2);
assert_eq!(g_tm.tm_mday, 21);
```4- Get the current time.
```rust
let p_tm = ptime::now();
println!("Current time: {}", p_tm);let p_tm_utc = ptime::now_utc();
println!("Current time at UTC: {}", p_tm_utc);
```5- Format the time.
```rust
let p_tm = ptime::from_gregorian(time::now());
println!("{}", p_tm.to_string("yyyy-MM-dd HH:mm:ss.ns"));/// yyyy, yyy, y year (e.g. 1394)
/// yy 2-digits representation of year (e.g. 94)
/// MMM the Persian name of month (e.g. فروردین)
/// MM 2-digits representation of month (e.g. 01)
/// M month (e.g. 1)
/// DD day of year (starting from 1)
/// D day of year (starting from 0)
/// dd 2-digits representation of day (e.g. 01)
/// d day (e.g. 1)
/// E the Persian name of weekday (e.g. شنبه)
/// e the Persian short name of weekday (e.g. ش)
/// A the Persian name of 12-Hour marker (e.g. قبل از ظهر)
/// a the Persian short name of 12-Hour marker (e.g. ق.ظ)
/// HH 2-digits representation of hour [00-23]
/// H hour [0-23]
/// kk 2-digits representation of hour [01-24]
/// k hour [1-24]
/// hh 2-digits representation of hour [01-12]
/// h hour [1-12]
/// KK 2-digits representation of hour [00-11]
/// K hour [0-11]
/// mm 2-digits representation of minute [00-59]
/// m minute [0-59]
/// ss 2-digits representation of seconds [00-59]
/// s seconds [0-59]
/// ns nanoseconds
```For more information, please check the test files in `tests` folder.