Giter VIP home page Giter VIP logo

rust-persian-calendar's Introduction

Rust Persian Calendar

crates.io Documentation Build Status 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. 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:

[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.

extern crate ptime;
extern crate time;

2- Convert Gregorian calendar to Persian calendar.

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.

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.

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.

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.

rust-persian-calendar's People

Contributors

yaa110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rust-persian-calendar's Issues

پیشنهاد توسعه

سلام پیشنهادی دارم برای افزودن قابلیت نمایش مناسبت به برنامه ای که توسعه دادید

الان که همه ی سیستم ها به اینترنت متصل هستند پیشنهاد میکنم ارتباط با ای پی آي های تقویم رو هم در این سورس خوب پیاده سازی کنید
خودم از این سرویس زیاد استفاده میکنم


وب سرویس تقویم فارسی

اطلاعات خوبی ارائه میده مثل وقایع و مناسبت های هر روز و دریافت رویداد در حالت شمسی و قمری و میلادی

Some leap year timestamps are not correctly calculated

years 1399 and 1403 are leap years

the timespec seconds value for 1399/12/30 and 1400/01/01 are different which is expected behavior
but same values for 1403/12/30 and 1404/01/01 are the same

minimal reproduction:

let time = ptime::from_persian_date(1399, 11, 30).unwrap().to_timespec().sec;
println!("{}", &time);
let time = ptime::from_persian_date(1400, 0, 1).unwrap().to_timespec().sec;
println!("{}", &time);


let time = ptime::from_persian_date(1403, 11, 30).unwrap().to_timespec().sec;
println!("{}", &time);
let time = ptime::from_persian_date(1404, 0, 1).unwrap().to_timespec().sec;
println!("{}", &time);

output

1616198400
1616284800
1742428800
1742428800

abstract time crate

Salam, thanks for your work!
Just wondering, shouldn't you abstract time crate instead of making users of your crate depend on it?
For example , users will need time::Duration and time::now you can reexport them with pub use time::{Duration,now} so anyone who uses your crate can just use ptime::{Duration,now] and more importantly doesn't have to add time crate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.