npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ni-datetime

v0.0.33

Published

Converter class for Farsi/Persian/Khorshidi, Islamic to Gregorian and vise versa.

Downloads

32

Readme

NiDatetime

Converter class for Jalali/Farsi/Persian to Gregorian and vise versa.

Note: Months are started from 1.

Installation

npm i ni-datetime

Example

const jalali = new NiJalaliDatetime(new Date());

console.log(jalali.__date); // internal date object
console.log(jalali.ymd);    // eg: {year:1390, month:1, date:12}
jalali.ymd = {year: 1360, month: 9, date: 12}

console.log(jalali.__date); // internal date object is changed

console.log(jalali.use(new Date()).ymd); // set to now and get ymd 

console.log(formatDate(jalali, Locales.fa_AF, "WWWW DD MMMM YYYY")); // eg: شنبه 9 قوس 1390

// -----------------------------------------

const gregorian = new NiGregorianDatetime(new Date());

console.log(gregorian.__date); // internal date object
console.log(gregorian.ymd);    // eg: {year:1980, month:1, date:12}
gregorian.ymd = {year: 2020, month: 9, date: 12}

console.log(gregorian.__date); // internal date object is changed

console.log(gregorian.use(new Date()).ymd); // set to now and get ymd

console.log(formatDate(gregorian, Locales.en_US, "WWWW DD MMMM YYYY")); // eg: Monday 20 January 2020

API

// wrapper for jalali date
export class NiJalaliDatetime    extends NiDatetime { }
// wrapper for islamic date
export class NiIslamicDatetime   extends NiDatetime { }
// wrapper for gregorian date
export class NiGregorianDatetime extends NiDatetime { }

// use to format a NiDatetime object
export const formatDate = (calendar: NiDatetime, 
                           locale: NiDatetimeLocale, 
                           format: string): string => { }

// list of available locales
export const Locales = {
    fa_AF: NiJalaliDatetime,
    fa_IR: NiJalaliDatetime,
    ar_SA: NiIslamicDatetime,
    en_US: NiGregorianDatetime
};


// base case
export class NiDatetime {

    __date: Date;

    constructor(date?: Date)                    { }

    use(date: Date)              : NiDatetime   { }

    get year()                   : number;
    get month()                  : number;
    get date()                   : number;
    get daysInMonth()            : number;
    get weeksFirstday()          : number;
    get weekDay()                : number;

    set ymd(ymd: Ymd)                           { }
    get ymd()                    : Ymd          { }

    get hours12()                : number       { }
    get hours()                  : number       { }
    set hours(hours: number)                    { }
    get minutes()                : number       { }
    set minutes(minutes: number)                { }
    get seconds()                : number       { }
    set seconds(seconds: number)                { }

    get am()                     : boolean      { }
    set am(toggle: boolean)                     { }

    get pm()                     : boolean      { }
    set pm(toggle: boolean)                     { }

    clone()                      : NiDatetime;
}

export class Ymd {
    year    : number;
    month   : number;
    date    : number;
}

export class Hms {
    hours   : number;
    minutes : number;
    seconds : number;
    isPM    : boolean;
}

export const Locales = {
    fa_AF: {
        name: 'fa_AF',
        new: () => new NiJalaliDatetime(),
        week: '#',
        dir: 'rtl',
        firstday: 6,
        weekends: [5],
        daysName: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'],
        daysNameShort: ['یک', 'دو', 'سه ', 'چهار', 'پنج', 'جمعه', 'شنبه'],
        daysNameMini: ['ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش'],
        monthsName: ['حمل', 'ثور', 'جوزا', 'سرطان', 'اسد', 'سنبله', 'میزان', 'عقرب', 'قوس', 'جدی', 'دلو', 'حوت'],
        monthsNameShort: ['حم', 'ثو', 'جو', 'سر', 'اس', 'سن', 'می', 'عق', 'قو', 'جد', 'دل', 'حو'],
        ampm: ['ق.ظ', 'ب.ظ'],
        AMPM: ['قبل از ظهر', 'بعد از ظهر'],
        today: 'امروز',
        clear: 'پاک'
    },
    fa_IR: {
        name: 'fa_IR',
        new: () => new NiJalaliDatetime(),
        week: '#',
        dir: 'rtl',
        firstday: 6,
        weekends: [5],
        daysName: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'],
        daysNameShort: ['یک', 'دو', 'سه ', 'چهار', 'پنج', 'جمعه', 'شنبه'],
        daysNameMini: ['ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش'],
        monthsName: ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور',
            'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'],
        monthsNameShort: ['فر', 'ار', 'خر', 'تی', 'مر', 'شه', 'مه', 'آب', 'آذ', 'دی', 'به', 'اس'],
        ampm: ['ق.ظ', 'ب.ظ'],
        AMPM: ['قبل از ظهر', 'بعد از ظهر'],
        today: 'امروز',
        clear: 'پاک'
    },
    ar_SA: {
        name: 'ar_SA',
        new: () => new NiIslamicDatetime(),
        week: '#',
        dir: 'rtl',
        firstday: 0,
        weekends: [5, 6],
        daysName: ['الأحد', 'الإثنين', 'الثُلاثاء', 'الأربعاء', 'الخميس', 'الجُمْعَة', 'السبت'],
        daysNameShort: ['أحد', 'إثنين', 'ثُلاثاء', 'أربعاء', 'خميس', 'جُمْعَة', 'سبت'],
        daysNameMini: ['ح', 'ث', 'ثُ', 'ع', 'خ', 'جُ', 'س'],
        monthsName: ['محرم', 'صفر', 'ربيع الأول', 'ربيع الثاني', 'جمادى الأولى',
            'جمادى الآخرة', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذوالقعدة', 'ذوالحجة'],
        monthsNameShort: ['محرم', 'صفر', 'ربيع ١', 'ربيع ٢', 'جمادى ١',
            'جمادى ٢', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذو القعدة', 'ذو الحجة'],
        ampm: ['ق.ظ', 'ب.ظ'],
        AMPM: ['قبل الظهر', 'بعد الظهر'],
        today: 'اليوم',
        clear: 'نظيف'
    },
    en_US: {
        name: 'en_US',
        new: () => new NiGregorianDatetime(),
        week: 'Wk',
        dir: 'ltr',
        firstday: 1,
        weekends: [6, 0],
        daysName: ['Sunday', 'Monday', 'Tuesday', 'Wedsday', 'Thursday', 'Friday', 'Saturday'],
        daysNameShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        daysNameMini: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
        monthsName: ['January', 'February', 'March', 'April', 'May', 'June',
            'July', 'August', 'September', 'October', 'November', 'December'],
        monthsNameShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        ampm: ['am', 'pm'],
        AMPM: ['AM', 'PM'],
        today: 'Today',
        clear: 'Clear'
    }
};

// use to convert Date(and time) to another timezone
// Note: this change time property of date, so if you call 
// timezone related functions on the returning date
// it will still show your local timezone.
// eg: Fri Feb 21 2020 18:59:51 GMT-0500 (GMT-05:00)
// this part can't be changed =>^^^^^^^^^^^^^^^^^^^^
// but the date and time part is changed.
export const toTimezone = (date: Date, 
                           targetTimezoneUTCOffset?: number): Date => {}

Available Formats

  • 'YYYY', 4 digit year
  • 'YY', 2 digit year
  • 'MMMM', long name of month
  • 'MMM', short name of month
  • 'MM', 2 digit month number
  • 'M', month number
  • 'DD', 2 digit date number
  • 'D', date number
  • 'WWWW', long name of week's day
  • 'WWW', short name of week's day
  • 'WW', mini name of week's day
  • 'HH', 2 digit hour (24h format)
  • 'hh', 2 digit hour (12h format)
  • 'H', hour (24h format)
  • 'h', hour (12h format)
  • 'mm', 2 digit minute
  • 'm', minute
  • 'ss', 2 digit second
  • 's', second
  • 'A', upper case AM/PM
  • 'a', lower case am/pm
  • 'z', time zone (eg: GMT-0500)
  • 'iso', iso format (eg: 2020-01-17T08:57:58.144Z)
  • 'mediumDate': 'WWW DD MMM, YYYY'
  • 'mediumTime': 'hh:mm a'
  • 'shortDate': 'YY/M/D'
  • 'shortTime': 'h:m a'
  • 'longDate': 'WWWW DD MMMM YYYY'
  • 'longTime': 'hh:mm:ss A'
  • 'medium': 'mediumDate mediumTime'
  • 'short': 'shortDate shortTime'
  • 'long': 'longDate longTime'

Credits: