date-bengali-revised
Revised Bengali Calendar
Revised Bengali Calendar calculations with conversion from/ to Gregorian Date.
The revised version of the Bengali calendar was officially adopted in Bangladesh in 1987.
The module supports:
- conversion from Gregorian Date to Bengali Date and vice versa
- conversion from javascript Date object to Bengali Date and vice versa
- formatting
Credits to Nuhil Mehdy for his project bangla-calendar.
The inital algorithm and the bengali names were taken from there. Thanks.
Table of Contents
Usage
Construct a new Bengali Date
Parameters
year: {Number|String}
, bengali year in bengal or latin digits
month: {Number|String}
, bengali month
day: {Number|String}
, bengali day
import Calendar from 'date-bengali-revised'
const Calendar = require('date-bengali-revised').default
let cal = new Calendar(1425, 1, 1)
cal = new Calendar('১৪২৫', '১', '১')
cal = new Calendar('১৪২৫', 'বৈশাখ', '১')
from Gregorian Date
Parameters
year: {Number}
, gregorian year
month: {Number}
, gregorian month
day: {Number}
, gregorian day
Returns: this for chaining
import Calendar from 'date-bengali-revised'
let cal = new Calendar()
cal.fromGregorian(2018, 4, 14)
to Gregorian Date
Convert Bengali Date back to Gregorian Date
Returns: {Object}
{year, month, day}
as gregorian date
let cal = new Calendar(1425, 1, 1)
let gdate = cal.toGregorian()
from Date
Calculate bengali calendar date from javascript Date object
Parameters
date: {Date}
- javascript Date object
Returns: this for chaining
let cal = new Calendar()
let date = new Date('2018-04-14T06:00:00Z')
cal.fromDate(date)
to Date
Returns: {Date}
- javascript Date object
let cal = new Calendar(1425, 1, 1)
let date = cal.toDate(date).toISOString()
formatting
Parameters
formatStr: {String}
- formatting string
Input | Description |
---|
Y | Year with any number of digits and sign |
Q | Season Name |
M | Month number |
MMMM | Month name |
D | Day of month |
dddd | Day name |
Returns: {String}
formatted date
let cal = new Calendar(1425, 1, 1)
cal.format()
cal.format('dddd D MMMM, Y [Q]')
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your
code to be distributed under the MIT license. You are also implicitly
verifying that all code is your original work or correctly attributed
with the source of its origin and License.
License
Copyright (c) 2018-present commenthol (MIT License)
See LICENSE for more info.
References