The implementation of the Persian (Solar Hijri) Calendar in Rust

Overview

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.

You might also like...
⚡️ Lightning-fast and minimal calendar command line. Written in Rust 🦀
⚡️ Lightning-fast and minimal calendar command line. Written in Rust 🦀

⚡️ Lightning-fast and minimal calendar command line. It's similar to cal. Written in Rust 🦀

The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more
The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more

Bloom The all-in-one private workspace Try it for free! You no longer trust tech monopolies with your data? You are done with your privacy invaded by

Scrypto Advent Calendar. Learn the new programming langage to build quick and secure DeFi applications.

Scrypto Advent Calendar I am publishing new Christmas related Scrypto examples every day from Dec 1st to Dec 25th. "Watch" this project to get notifie

carl is a calendar for the commandline.
carl is a calendar for the commandline.

carl is a calendar for the commandline. It tries to mimic the various cal(1) implementations out there, but also adds enhanced features like colors and ical support.

a day-planner/calendar app based on egui
a day-planner/calendar app based on egui

Malakal Malakal is a day planner application. I crafted it because I was not able to find a comfortable calendar application for Linux. I myself have

Linkal - A public-calendar aggregator server

Linkal Linkal is a public-calendar aggregator server. Given a set a public calendars links, it can make a CalDav client believe all these calendars ar

🚫📆 Serverless calendar built with shuttle.rs
🚫📆 Serverless calendar built with shuttle.rs

zerocal 🚫 📆 Welcome to zerocal, the serverless calendar. It allows you to create calendar invites from the convenience of your terminal! 🔗 Here's m

A simple program for handling Ethiopian calendar dates.

Mek’ut’erīya A simple program for handling Ethiopian calendar dates. Installation cargo install --git https://github.com/frectonz/mek-ut-er-ya If you

Get your loadshedding schedule in your calendar and never be left in the dark! Open-source, up-to-date, and developer friendly.
Get your loadshedding schedule in your calendar and never be left in the dark! Open-source, up-to-date, and developer friendly.

Loadshedding schedules in your digital calendar. No apps, no ads, up-to-date, and developer friendly. Get it • Key Features • Using the data • Project

An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.

regex A Rust library for parsing, compiling, and executing regular expressions. Its syntax is similar to Perl-style regular expressions, but lacks a f

rinflux is Rust based influx client implementation that have been inspired from influx other language implementation, developed with 💖
rinflux is Rust based influx client implementation that have been inspired from influx other language implementation, developed with 💖

Unofficial InfluxDB Driver for Rust This library is a work in progress. This means a feature you might need is not implemented yet or could be handled

A SIMD implementation of Keccak256 for aarch64, forked from Remco Bloeman's Goldilocks K12 implementation.

keccak256-aarch64 Warning This crate was forked from real cryptographers (Goldilocks by Remco Bloeman), by not a real cryptographer. Do not use this k

MessagePack implementation for Rust / msgpack.org[Rust]

RMP - Rust MessagePack RMP is a pure Rust MessagePack implementation. This repository consists of three separate crates: the RMP core and two implemen

Stretto is a Rust implementation for ristretto. A high performance memory-bound Rust cache.

Stretto is a Rust implementation for ristretto. A high performance memory-bound Rust cache.

Rust implementation of Andrej Karpathy's micrograd for purposes of learning both ML and Rust.

micrograd_rs Rust implementation of Andrej Karpathy's micrograd for purposes of learning both ML and Rust. Main takeaways Basically the same takeaways

A rust chess implementation using a neural network scoring function built on huggingface/candle + rust + wasm

Rusty Chess What is it? Rusty Chess aims to be a high quality embeddable chess engine that runs entirely locally in the browser (no backend required).

Rust/Axum server implementation with PCR(Prisma Client Rust)
Rust/Axum server implementation with PCR(Prisma Client Rust)

Realworld Rust Axum Prisma This project utilizes Rust with the Axum v0.7 framework along with the Prisma Client Rust to build a realworld application.

Marvin-Blockchain-Rust: A Rust-based blockchain implementation, part of the Marvin blockchain project.

Marvin Blockchain - Rust Implementation Welcome to the Rust implementation of the Marvin Blockchain. This project is part of a comparative study on bu

Userspace WireGuard® Implementation in Rust
Userspace WireGuard® Implementation in Rust

BoringTun BoringTun is an implementation of the WireGuard® protocol designed for portability and speed. BoringTun is successfully deployed on millions

Comments
  • abstract time crate

    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.

    opened by sigmaSd 5
  • abstract time crate

    abstract time crate

    1 - abstracted time::Duration, I think that suffice but I'm not 100% sure. 2 - Change tests accordingly and keep time crate where its useful. 3 - fixed some formatting in doc.

    opened by sigmaSd 2
  • پیشنهاد توسعه

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

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

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

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

    اطلاعات خوبی ارائه میده مثل وقایع و مناسبت های هر روز و دریافت رویداد در حالت شمسی و قمری و میلادی
    opened by mehrdadashtari 1
Cocom - NTP client written in Rust

Cocom is an implementation of the NTP-protocol, to receive the time from NTP-server. The client does not necessarily need arguments.

Maximilian Sonnenburg 7 Dec 2, 2022
Time series anomaly detection for Rust

AnomalyDetection.rs Time series AnomalyDetection for Rust Learn how it works Installation Add this line to your application’s Cargo.toml under [depend

Andrew Kane 6 Nov 21, 2022
eos is a datetime library for Rust, aimed at being robust, simple, and easy to use

eos eos is a datetime library for Rust, aimed at being robust, simple, and easy to use. eos is made with the assumption of operating under a proleptic

Danny 51 Dec 19, 2022
A pure Rust reimplementation of libc functions localtime, gmtime and mktime.

tz-rs A pure Rust reimplementation of libc functions localtime, gmtime and mktime. This crate allows to convert between a Unix timestamp and a calenda

null 159 Jan 2, 2023
Date and time library for Rust. Feature rich, lightweight and easy-to-use.

Astrolabe Date and time library for Rust. Feature rich, lightweight and easy-to-use. Documentation | Github | Crate Example Status Astrolabe is curren

Jasmin 2 Sep 2, 2022
Convert Hygea calendar to an iCal file to easily import it to Google Calendar (Rust version)

Hygea to iCal Goal Hygea provides a calendar via PDF and an application called Recycle. I just wanted to use an iCal file to import it in my calendar.

Guillaume Quittet 2 Oct 28, 2021
Synchronizes Southern California Mountaineers Association (SCMA) calendar events to Google Calendar.

SCMA Google Calendar Sync Synchronizes Southern California Mountaineers Association (SCMA) calendar events to Google Calendar. Credentials SCMA websit

Rob Donnelly 1 Aug 11, 2022
3D Solar System visualization

Description This project is an unrealistic 3D Solar System visualization. It was made for Computer graphics course, that I took at the University of W

Michał Sala 1 Feb 22, 2022
An anthology of a variety of tools for the Persian language in Rust

persian-tools A set of helpers to sanitize, convert or transform information related to Persian language and/or Iran. Features Feature Status National

null 17 Dec 25, 2021
List of Persian Colors and hex colors for CSS, SCSS, PHP, JS, Python, and Ruby.

Persian Colors (Iranian colors) List of Persian Colors and hex colors for CSS, SCSS, PHP, C++, QML, JS, Python, Ruby and CSharp. Persian colors Name H

Max Base 12 Sep 3, 2022