Coder Social home page Coder Social logo

alitaheri / moment-jalaali Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jalaali/moment-jalaali

0.0 2.0 0.0 270 KB

A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.

License: MIT License

Makefile 0.86% JavaScript 99.14%

moment-jalaali's Introduction

moment-jalaali

A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.

Build Status

About

Jalali calendar is a solar calendar that was used in Persia, variants of which today are still in use in Iran as well as Afghanistan. Read more on Wikipedia or see Calendar Converter.

This plugin adds Jalaali calendar support to momentjs library.

Calendar conversion is based on the algorithm provided by Kazimierz M. Borkowski and has a very good performance.

Where to use it

Like momentjs, moment-jalaali works in browser and in Node.js.

Node.js

npm install moment-jalaali
var moment = require('moment-jalaali')
moment().format('jYYYY/jM/jD')

Browser

It is recommended to use component. Otherwise, you may use the build/moment-jalaali.js file.

<script src="moment.js"></script>
<script src="moment-jalaali.js"></script>
<script>
  moment().format('jYYYY/jM/jD')
</script>

API

This plugin tries to mimic momentjs api. Basically, when you want to format or parse a string, just add a j to the format token like 'jYYYY' or 'jM'. For example:

m = moment('1360/5/26', 'jYYYY/jM/jD') // Parse a Jalaali date
m.format('jYYYY/jM/jD [is] YYYY/M/D') // 1360/5/26 is 1981/8/17

m.jYear() // 1360
m.jMonth() // 4
m.jDate() // 26
m.jDayOfYear() // 150
m.jWeek() // 22
m.jWeekYear() // 1360

m.add(1, 'jYear')
m.add(2, 'jMonth')
m.add(3, 'day')
m.format('jYYYY/jM/jD') // 1361/7/29

m.jMonth(11)
m.startOf('jMonth')
m.format('jYYYY/jM/jD') // 1361/12/1

m.jYear(1392)
m.startOf('jYear')
m.format('jYYYY/jM/jD') // 1392/1/1

m.subtract(1, 'jYear')
m.subtract(1, 'jMonth')
m.format('jYYYY/jM/jD') // 1390/12/1

moment('1391/12/30', 'jYYYY/jMM/jDD').isValid() // true (leap year)
moment('1392/12/30', 'jYYYY/jMM/jDD').isValid() // false (common year)
moment.jIsLeapYear(1391) // true
moment.jIsLeapYear(1392) // false

moment('1392/6/3 16:40', 'jYYYY/jM/jD HH:mm').format('YYYY-M-D HH:mm:ss') // 2013-8-25 16:40:00

moment('2013-8-25 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('jMonth').format('jYYYY/jM/jD HH:mm:ss') // 1392/6/31 23:59:59

// Complex parse:
moment('1981 5 17', 'YYYY jM D').format('YYYY/MM/DD') // 1981/07/17

To add Persian language, use loadPersian method:

moment.loadPersian()

moment-hijri

Another calendar system plugin for momentjs is moment-hijri created by @xsoh.

License

MIT

moment-jalaali's People

Contributors

alitaheri avatar arastu avatar behrang avatar bitdeli-chef avatar mvalipour avatar

Watchers

 avatar  avatar

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.