Skip to content

Commit

Permalink
fix(calendars/ethiopian): fix month number in ethiopian pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
sara-gnucoop authored and trik committed Jan 10, 2022
1 parent 27bcb62 commit efc186e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/calendars/ethiopian/calendar-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class AjfEthiopianCalendarService extends AjfCalendarService {
const ecDate = EthiopianDate.gregorianToEthiopian(viewDate);
let curYear: number = ecDate.getFullYear();
let firstYear = curYear - (curYear % 10) + 1;
let curDate: Date = EthiopianDate.ethiopianToGregorian(firstYear, 1, 1);
let curDate: Date = EthiopianDate.ethiopianToGregorian(firstYear, 0, 1);

let rows: AjfCalendarEntry[][] = [];
for (let i = 0; i < 4; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/calendars/ethiopian/ethiopian-date-pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AjfEthiopianDatePipe implements PipeTransform {
try {
const ed = EthiopianDate.gregorianToEthiopian(value);
const date = `0${ed.getDate()}`.slice(-2);
const month = `0${ed.getMonth()}`.slice(-2);
const month = `0${ed.getMonth() + 1}`.slice(-2);
return `${date}/${month}/${ed.getFullYear()}`;
} catch (e) {
return null;
Expand Down
18 changes: 12 additions & 6 deletions src/calendars/ethiopian/ethiopian-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ export class EthiopianDate {
];
this._gc = EthiopianDate.ethiopianToGregorian(this._year, this._month, this._date);
} else if (typeof val === 'object' && val instanceof Date) {
const result = EthiopianDate.gregorianToEthiopian(
val.getFullYear(),
val.getMonth() + 1,
val.getDate(),
);
const result = EthiopianDate.gregorianToEthiopian(val);
[this._year, this._month, this._date] = [
result.getFullYear(),
result.getMonth(),
Expand Down Expand Up @@ -140,7 +136,7 @@ export class EthiopianDate {
* @param val - A numeric year value if the second and third parameters are
* provided, it should be a date string if not
* @param month A zero-based numeric value for the month
* (0 for January, 11 for December)
* (0 for መስከረም, 12 for ጳጉሜን)
* @param day A numeric value equal for the day of the month.
*
* @api public
Expand Down Expand Up @@ -170,6 +166,16 @@ export class EthiopianDate {
return new Date(gc[0], gc[1] - 1, gc[2]);
}

/**
*
* @param val - A numeric year value if the second and third parameters are
* provided, it should be a date string if not
* @param month A zero-based numeric value for the month
* (0 for January, 11 for December)
* @param day A numeric value equal for the day of the month.
*
* @api public
*/
static gregorianToEthiopian(
val?: Date | string | number,
month?: number,
Expand Down

0 comments on commit efc186e

Please sign in to comment.