Skip to content

Commit

Permalink
Ensure that former datetimes are OK
Browse files Browse the repository at this point in the history
  • Loading branch information
user1 committed Nov 7, 2019
1 parent 307a418 commit e803c46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/buetDateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function buetDateConverter(inputDate)
// Modifications as per new convention from 19.OCT.2019
// Reference: https://www.bbc.com/bengali/news-50082316
var leapYearMonthIndex = 10, leapYearMonthDays = 30;
//*
if( d < new Date(2018,3,14) ) // Additional code to respect convention before 1426 bengali year
//* Ensure that dates before the convention match with paper-published days
if( d < new Date(2018,3,14) && d > new Date(1970,0,1) ) // Additional code to respect convention before 1426 bengali year
{
leapYearMonthDays = 31;
this.formatConvertList.multiplierBD[5] = 30;
Expand Down
19 changes: 10 additions & 9 deletions test/buetDateTime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ describe("Rarely used formats", () => {
describe("Leap year", () => {

it("User provided date is properly converted", () => {
// 2012-02-29T21:31:24.029+0000
let leapYear = localToUTC(new Date(1330551084029));
// Wednesday, February 29, 2012 10:24:44.029 AM
let leapYear = localToUTC(new Date(1330511084029));
let convertedLeapYear = new buetDateConverter(leapYear);

expect(convertedLeapYear.convert("l, j F Y, A g:i")).toBe('বুধবার, ১৭ ফাল্গুন ১৪১৮, রাত ৯:৩১');
expect(convertedLeapYear.convert("l, j F Y, A g:i")).toBe('বুধবার, ১৭ ফাল্গুন ১৪১৮, সকাল ১০:২৪');
});

it("Bengali calendar date after leap year day", () => {
Expand All @@ -70,21 +70,22 @@ describe("Leap year", () => {
describe("Example dates for changed convention of 2019", () => {

it('Datetime after setting Ashwin to 31days', () => {
// Sunday, November 3, 2019 7:15:37 PM
let epochTime = new buetDateConverter(localToUTC(new Date(1572808537000)));
expect(epochTime.convert("Y-m-d")).toBe('১৪২৬-৭-১৮');
expect(true).toBe(true);
// Fri, 08 Nov 2019 18:41:30 +0000
let epochTime = new buetDateConverter(localToUTC(new Date(1573238490000)));
expect(epochTime.convert("d F Y")).toBe('২৩ কার্তিক ১৪২৬');
});

/*
it('International Mother Language day - 1952', () => {
// 1952-02-21T00:00:01.001+0000 --> this is before epoch, so regular date object is provided
let epochTime = new buetDateConverter(localToUTC(new Date('1952-02-21T00:00:01')));
expect(epochTime.convert("Y-m-d")).toBe('১৩৫৮-১১-৮');
});
*/

it('International Mother Language day - 2020', () => {
// Friday, February 21, 2020 12:00:01 AM
let epochTime = new buetDateConverter(localToUTC(new Date(1582243201000)));
// Friday, February 21, 2020 12:00:01 AM GMT+06:00
let epochTime = new buetDateConverter(localToUTC(new Date(1582221601000)));
expect(epochTime.convert("Y-m-d")).toBe('১৪২৬-১১-৮');
});
});

0 comments on commit e803c46

Please sign in to comment.