pyno-date
v1.0.0
Published
A lightweight Angular library for converting and formatting Jalali and Gregorian dates.
Maintainers
Readme
🗓️ pyno-date
A lightweight Angular library for converting and formatting Gregorian and Jalali (Persian) dates. Inspired by PHP's date formatting system.
📦 Installation
npm install pyno-date⚙️ Setup
Import the module into your Angular app module file or your standalone component:
For module-based apps:
import { PynoDateModule } from 'pyno-date';
@NgModule({
imports: [
// ... ,
PynoDateModule
]
})
export class AppModule {}For standalone components:
import { PynoDateModule } from 'pyno-date';
@Component({
imports: [
// ... ,
PynoDateModule
]
})🧪 Usage in Component
import { PynoDateModule, PynoDateService } from 'pyno-date';
export class AppComponent implements OnInit{
constructor(pynoDate: PynoDateService) {}
ngOnInit(){
// Convert Gregorian date to Jalali (Persian) date
console.log( this.pynoDate.gregorianToJalali(2025, 5, 28, '13:55') );
/*{
jYear: 1404,
jMonth: 3,
jDay: 4,
time: "13:55"
}*/
// Convert Jalali (Persian) date to Gregorian date
console.log( this.pynoDate.jalaliToGregorian(1404, 12, 26, '18:00') );
/*{
gYear: 2026,
gMonth: 3,
gDay: 17,
time: "18:00"
}*/
// Get current timestamp
console.log( this.pynoDate.time() ); //1748425678
// Get timestamp of a Gregorian or Jalali (Persian) date (and time)
console.log ( this.pynoDate.getTime( '2025-05-28 13:55' ), 'gregorian' ); //1748440500
console.log ( this.pynoDate.getTime( {year: 2025, month: 5, day: 28, time: '13:55'} ), 'gregorian' ); //1748440500
console.log ( this.pynoDate.getTime( '1404/03/25 14:57' ), 'jalali' ); //1749999420
console.log ( this.pynoDate.getTime( {year: 1404, month: 3, day: 25, time: '14:57'} ), 'jalali' ); //1748440500
//Get current Gregorian date in any format
console.log( this.pynoDate.gDate( 'Y-m-d H:i:s' ) ); // 2025-05-28 13:55:46
// Get Gregorian date from timestamp in any format:
console.log( this.pynoDate.gDate( 'F jS, Y - H:i', 1748440500 ) ); // May 28th, 2005 - 13:55
//Get current Jalali date in any format
console.log( this.pynoDate.jDate( 'Y/m/d H:i:s' ) ); // 1404/03/07 13:55:46
// Get Gregorian date from timestamp in any format:
console.log( this.pynoDate.jDate( 'l j F Y', 1748440500 ) ); // سه شنبه 24 خرداد 1404
}
}
🔧 Pipes
1. jDate
Converts a Gregorian date to Jalali.
{{ '2025-03-21' | jDate }}
<!-- Output: 1404/01/01 -->
{{ '2025-03-21 13:55' | jDate }}
<!-- Output: 1404/01/01 13:55 -->
{{ '2025-03-21 13:55' | jDate: 'l j F Y' }}
<!-- Output: جمعه 1 فروردین 1404 -->
{{ {year: 2005, month: 3, day: 21} | jDate: 'Y/m/d' }}
<!-- Output: 1404/01/01 -->2. gDate
Converts a Jalali date to Gregorian.
{{ '1404/01/01' | gDate }}
<!-- Output: 2025-03-21 -->
{{ '1404/01/01 13:55' | gDate }}
<!-- Output: 2025-03-21 13:55 -->
{{ '1404/01/01 13:55' | gDate: 'l j F Y' }}
<!-- Output: Friday 21 March 2025 -->
{{ {year: 1404, month: 1, day: 1} | gDate: 'Y-m-d' }}
<!-- Output: 2025-03-21 -->3. jFormat
Formats a Jalali date with a custom pattern.
{{ '1404/01/01 13:55' | jFormat: 'Y-m-d' }}
<!-- Output: 1404-01-01 -->
{{ '1404/01/01 ' | jFormat: 'l j F Y' }}
<!-- Output: جمعه 1 فروردین 1404 -->4. gFormat
Formats a Gregorian date with a custom pattern.
{{ '2025-03-21 13:55' | jFormat: 'Y/m/d' }}
<!-- Output: 2025/03/21 -->
{{ '2025-03-21 ' | jFormat: 'l j F Y' }}
<!-- Output: Friday 21 March 2025 -->📅 Format Reference
| Format | En Description | Fa Description | Gregorian Example | Jalali Example |
|--------|-------------------------------------------------------------|----------------------------------------|-----------------------------------------|-----------------------------------------|
| d | The two digit day of the month | روز ماه بصورت دو رقمی | 01 to 31 | 01 to 31 |
| D | A 3-letter textual representation of a day | حرف اول نام روز هفته | Sun to Sat | ش to ج |
| j | The day of the month without leading zeros | روز ماه بصورت یک رقمی یا دو رقمی | 1 to 31 | 1 to 31 |
| l | A full textual representation of a day | نام روز هفته | Sunday to Saturday | شنبه to جمعه |
| N | The ISO-8601 numeric representation of a day | عدد روز در هفته | 1 for Monday, 7 for Sunday | 1 برای یک شنبه، 7 برای شنبه |
| S | The English ordinal suffix for the day of the month | واژه ام برای بعد از عدد روز | st nd rd th | ام |
| w | A numeric representation of the day | عدد روز در هفته (فارسی) | 0 for Sunday, 7 for Saturday | 0 برای شنبه، 6 برای جمعه |
| z | The day of the year | عدد روز در سال | From 0 to 365 | From 0 to 365 |
| W | The ISO-8601 week number of year (weeks starting on Monday) | عدد دورقمی هفته در سال | From 00 to 53 | From 00 to 53 |
| F | A full textual representation of a month | نام کامل ماه | January to December | فروردین to اسفند |
| m | A two-digit representation of a month | عدد ماه بصورت دورقمی | 01 to 12 | 01 to 12 |
| M | A 3-letter representation of a month | نام مختصر ماه | Jan to Dec | فر to اس |
| n | A numeric representation of a month, without leading zeros | عدد ماه | 1 to 12 | 1 to 12 |
| t | The number of days in the given month | تعداد روز در ماه | 28 to 31 | 29 to 31 |
| L | Whether it's a leap year | سال کبیثه | 1 if it is a leap year, 0 otherwise | 1 if it is a leap year, 0 otherwise |
| o | The ISO-8601 year number | سال هفته ای (به عدد) چهار رقمی | 2025 | 1404 |
| Y | A four digit representation of a year | سال (به عدد) چهار رقمی | 2025 | 1404 |
| y | A two digit representation of a year | | 25 | 04 |
| a | Lowercase am or pm | خلاصه قبل از ظهر یا بعد از ظهر | am pm | ق.ظ ب.ظ |
| A | Uppercase AM or PM | قبل از ظهر و بعد از ظهر | AM PM | قبل از ظهر بعد از ظهر |
| g | 12-hour format of an hour | ساعت در روز - 12 ساعته | 1 to 12 | 1 to 12 |
| G | 24-hour format of an hour | ساعت در روز - 24 ساعته | 0 to 23 | 0 to 23 |
| h | A two digit 12-hour format of an hour | ساعت در روز - 12 ساعته - دو رقمی | 01 to 12 | 01 to 12 |
| H | A two digit 24-hour format of an hour | ساعت در روز - 24 ساعته - دو رقمی | 01 to 23 | 01 to 23 |
| i | A two digit representation of a minute | دقیقه بصورت دورقمی | 00 to 59 | 00 to 59 |
| s | A two digit representation of a second | ثانیه بصورت دورقمی | 00 to 59 | 00 to 59 |
| O | Difference to Greenwich time (GMT) in hours | تفاوت زمانی با گرینویج به ساعت | +0100 | +0100 |
| P | Difference to Greenwich time (GMT) in hours:minutes | تفاوت زمانی با گرینویچ به ساعت و دقیقه | +01:30 | +01:30 |
| c | The ISO-8601 date | فرمت استاندارد تاریخ و ساعت | 2025-05-31 16:34:42 | 1404/03/10 16:34:42 |
| C | Century number | شماره قرن | 21 | 15 |
| r | The RFC 2822 formatted date | فرمت استاندارد روز، تاریخ و ساعت | Fri, 12 Apr 2025 12:01:05 | جمعه، 10 خرداد 1404 16:34:42 |
| U | The seconds since the Unix Epoch | ثانیه از زمان شروع Unix | 1748688816 | 1748688816 |
🧠 License
MIT d
