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

mds.persian.datetime

v1.9.0

Published

Persian DateTime in TypeScript

Downloads

126

Readme

Persian DateTime In TypeScript

Persian datetime library in TypeScript for using in TypeScript projects like angular

Install

Use npm to install:

npm install mds.persian.datetime@latest --save

Then import Mds namespace it in your project

import { Mds } from 'mds.persian.datetime'
import PersianDateTime = Mds.PersianDateTime;

Define new object

You can define new PersianDateTime object with following ways:

  • Constructor and with date object
let pc = new PersianDateTime(new Date());
  • FromPersianDate
let pc = PersianDateTime.fromPersianDate(1396, 03, 14)
  • FromPersianDateTime
let pc = PersianDateTime.fromPersianDateTime(1396, 03, 14, 23, 12, 22, 10)
  • Parse

You can parse different date string

let pc1 = PersianDateTime.parse('14 خرداد 1396')
let pc2 = PersianDateTime.parse('1396-03-16')
let pc3 = PersianDateTime.parse('1396-03-16  22:12:30')
let pc4 = PersianDateTime.parse('14 خرداد 1396 ساعت 22:10')
let pc5 = PersianDateTime.parse('1396/01/03')
let pc6 = PersianDateTime.parse('یکشنبه 14 خرداد 1396')
  • Now property

you can get current datetime with now property

let pc = PersianDateTime.now
  • Today property

you can get current date without time with today property

let pc = PersianDateTime.today

Properties

englishNumber: boolean // English number or persian number in output of object
year: number // Year of selected date
shortYear: number // year with two digit
month: number // month number in year, start from 1
monthName: string // month name => فروردین، اردیبهشت، ...
dayOfWeek: number // day name in week, PersianDayOfWeek enum
dayOfWeekGregorian: number // day name in week, GregorianDayOfWeek enum
startDayOfMonthDayOfWeek: string // start day of week in month
endDayOfMonthDayOfWeek: string // end day of week in month
dayOfWeekName: string // name of day in week, شنبه، یکشنبه ....
getShortDayOfWeekName: string // first character of dayOfWeekName ش، ی ، د، ...
getMonthDays: number // days number in month
hour: number // hour from 1 to 24
shortHour: number // hour from 1 to 12
minute: number
second: number
millisecond: number
isLeapYear: boolean // is year leap آیا سال کبیسه است
getPersianAmPmEnum: string // show قبل از ظهر or بعد از ظهر
getShortPersianAmPmEnum: string // short ق.ظ or ب.ظ
static getPersianMonthNames: string[] // list of all persian months فروردین، اردیبهشت، ...
static getPersianMonthIndex: number // get index of persian month with persian month name
static getPersianWeekdayNames: string[]  // list of all persian week day names
static getPersianWeekdayNamesShort: string[]  // list of all short persian week day names
static getGregorianWeekdayNames: string[] // get list of all gregorian week day names
timeOfDay: string // get time like 13:47:40:530
longTimeOfDay: string // get time like ساعت 01:47:40:530 ب.ظ
shortTimeOfDay: string // get time like 01:47:40 ب.ظ
date: PersianDateTime // get new object of date without time

Methods

static getPersianMonthIndex(persianMonthName: string): number // Get persian index of input month name
static getPersianWeekdayIndex(persianWeekdayName: string): number // Get persian index of input week day name
static getGregorianWeekdayIndex(gregorianWeekdayName: string): number // Get gregorian index of input week day name
static getGregorianMonthNameIndex(gregorianMonthName: string): number // Get gregorian index of input month name
/**
 * convert datetime to string
 * فرمت پیش فرض 1393/09/14   13:49:40 
 * yyyy: year with four digit
 * yy: year with two digit
 * MMMM: persian month name
 * MM: month number with two digit
 * M: month number
 * dddd: persian week day name
 * dd: month day number with two digit
 * d: month day number
 * HH: hour with two digit from 0 to 24
 * H: hour from 0 to 24
 * hh: hour with two digit from 0 to 12
 * h: hour from 0 to 12
 * mm: minute with two digit
 * m: minute
 * ss: second with two digit
 * s: second 
 * fff: millisecond with three digit
 * ff: millisecond with two digit
 * f: millisecond
 * tt: ب.ظ or ق.ظ 
 * t: first character of ب.ظ or ق.ظ
 **/
toString(format: string = ''): string
addYears(years: number): PersianDateTime // add years to datetime object
addMonths(years: number): PersianDateTime // add months to datetime object
addDays(days: number): PersianDateTime // add days to datetime object
addHours(hours: number): PersianDateTime // add hours to datetime object
addMinutes(minutes: number): PersianDateTime // add minutes to datetime object
addSeconds(seconds: number): PersianDateTime // add seconds to datetime object
addMilliSeconds(milliseconds: number): PersianDateTime // add milliseconds to datetime object
// get date object
toDate(): Date
setPersianYear(persianYear: number): PersianDateTime // set persian year
setPersianMonth(persianMonth: number): PersianDateTime // set persian month
setPersianDay(persianDay: number): PersianDateTime // set persian day
setHour(hour: number): PersianDateTime // set hour
setMinute(minute: number): PersianDateTime // set minute
setSecond(second: number): PersianDateTime // set second
setMillisecond(millisecond: number): PersianDateTime // set millisecond
setPersianDate(year: number, month: number, day: number): PersianDateTime // set persian date
setTime(hour: number, minute: number, second: number, millisecond: number): PersianDateTime // set time
getShortNumber(): number // Year - Month - Day as number => 13970624
getLongNumber(): number // Year - Month - Day - Hour - Minute - Second as number => 13970624031526

DateTimePicker

If you need a DateTimePicker for your apps, I recommend the following: https://github.com/Mds92/MD.BootstrapPersianDateTimePicker Mds Angular Persian and Gregorian DateTimePicker