Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Islamic calendar #15

Merged
merged 8 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: required
language: node_js

node_js:
- "8"
- "10.9.0"

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@angular/platform-browser-dynamic": "^7.2.7",
"@angular/router": "^7.2.7",
"core-js": "^2.5.4",
"jdnconvertiblecalendar": "0.0.3",
"jdnconvertiblecalendar": "0.0.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
CalendarPeriod,
GregorianCalendarDate,
JDNConvertibleCalendar,
JDNConvertibleConversionModule,
JDNPeriod,
JulianCalendarDate
} from 'jdnconvertiblecalendar';
import {JDNConvertibleCalendarModule} from "jdnconvertiblecalendar/dist/src/JDNConvertibleCalendar";
import IslamicCalendarDate = JDNConvertibleCalendarModule.IslamicCalendarDate;


@Injectable()
Expand Down Expand Up @@ -105,6 +105,10 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl
this._activeCalendarFormat = 'Julian';
return dateMod.convertCalendar('Julian');

case 'Islamic':
this._activeCalendarFormat = 'Islamic';
return dateMod.convertCalendar('Islamic');

default:
// invalid format
return dateMod;
Expand Down Expand Up @@ -138,8 +142,11 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl
}

getMonthNames(style: 'long' | 'short' | 'narrow'): string[] {
// TODO: implement this properly, taking calendar format and locale into account
return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
if (this._activeCalendarFormat === 'Julian' || this._activeCalendarFormat === 'Gregorian') {
return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
} else if (this._activeCalendarFormat === 'Islamic') {
return ['Muharram', 'Safar', 'Rabīʿ al Awwal','Rabīʿ al Ththānī', 'Jumādá al Ūlá', 'Jumādá al Ākhirah', 'Rajab','Sha‘bān', 'Ramadān','Shawwāl','Dhū al Qa‘dah', 'Dhū al Hijjah'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlQuraian @benjamingeer Could you have a look at the month names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjamingeer Could we have look at this next week? We can also try without transliteration, but perhaps there will be RTL issue (CSS).

Copy link

@benjamingeer benjamingeer Aug 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally both Arabic script and transliteration would be supported. I would transliterate them like this:

Transliteration Arabic
Muḥarram محرم
Ṣafar صفر
Rabīʿ al-Awwal ربيع الأول
Rabīʿ al-Thānī ربيع الثاني
Jumādā al-Ūlā جمادى الأولى
Jumādā al-Ākhirah جمادى الآخرة
Rajab رجب
Shaʿbān شعبان
Ramaḍān رمضان
Shawwāl شوال
Dhū al-Qaʿdah ذو القعدة
Dhū al-Ḥijjah ذو الججة

We can look at this next week.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you very much!

I have to see how the UI behaves with Arabic script.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
}

getDateNames(): string[] {
Expand All @@ -153,8 +160,11 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl
}

getDayOfWeekNames(style: 'long' | 'short' | 'narrow') {
// TODO: implement this properly, taking calendar format and locale into account
return ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'];
if (this._activeCalendarFormat === 'Julian' || this._activeCalendarFormat === 'Gregorian') {
return ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'];
} else if (this._activeCalendarFormat === 'Islamic') {
return ['al-Aḥad', 'al-Ithnayn', 'ath-Thulāthā’', ' al-Arba‘ā’', 'al-Khamīs', 'al-Jumu\'ah', 'as-Sabt'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlQuraian @benjamingeer Could you have a look at the weekdays?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transliteration Arabic
al-Aḥad الأحد
al-Ithnayn الإثنين
al-Thulāthāʾ الثلاثاء
al-Arbiʿāʾ الأربعاء
al-Khamīs الخميس
al-Jumʿah الجمعة‎
al-Sabt السبت

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlQuraian Thanks! Once this PR is merged, I will come up with a stackblitz example to try it out.

}
}

getYearName(date: JDNConvertibleCalendar): string {
Expand Down Expand Up @@ -182,6 +192,9 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl

case 'Julian':
return new JulianCalendarDate(jdnPeriod);

case 'Islamic':
return new IslamicCalendarDate(jdnPeriod);
}

}
Expand All @@ -205,6 +218,9 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl

case 'Julian':
return new JulianCalendarDate(new CalendarPeriod(calDate, calDate));

case 'Islamic':
return new IslamicCalendarDate(new CalendarPeriod(calDate, calDate));
}
}

Expand Down Expand Up @@ -356,8 +372,6 @@ export class JDNConvertibleCalendarDateAdapter extends DateAdapter<JDNConvertibl

const gregorianCalPeriod = gregorianCal.toCalendarPeriod();

console.log('to iso');

return `${JDNConvertibleCalendarDateAdapter.addLeadingZeroToNumber(gregorianCalPeriod.periodStart.year, 4)}-${JDNConvertibleCalendarDateAdapter.addLeadingZeroToNumber(gregorianCalPeriod.periodStart.month, 2)}-${JDNConvertibleCalendarDateAdapter.addLeadingZeroToNumber(gregorianCalPeriod.periodStart.day, 2)}`;

}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class HeaderComponent<D> implements OnInit {
*
* @param {"Gregorian" | "Julian"} calendar the target calendar format.
*/
convertCalendar(calendar: 'Gregorian' | 'Julian') {
convertCalendar(calendar: 'Gregorian' | 'Julian' | 'Islamic') {

if (this._dateAdapter instanceof JDNConvertibleCalendarDateAdapter) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba After conversion to the Islamic calendar, the weekdays are not updated:

conversion

However, when I close and reopen the datepicker widget, the names are updated correctly.

Do I have to call an additional method after each conversion (similar to updateTodaysDate)?

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4051,10 +4051,10 @@ jasminewd2@^2.1.0:
resolved "https://registry.yarnpkg.com/jasminewd2/-/jasminewd2-2.2.0.tgz#e37cf0b17f199cce23bea71b2039395246b4ec4e"
integrity sha1-43zwsX8ZnM4jvqcbIDk5Uka07E4=

jdnconvertiblecalendar@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/jdnconvertiblecalendar/-/jdnconvertiblecalendar-0.0.3.tgz#a4e6106340b27bc06bf08cd00912960c666693cc"
integrity sha512-AxqmzIkHLE/iEZuej5S9zTqXOAvtHJIk6iMPM3tLBha9UBclxXqXGeqJtclMflVHuvpzm06e0zJ2YVCSA8vtQg==
jdnconvertiblecalendar@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/jdnconvertiblecalendar/-/jdnconvertiblecalendar-0.0.4.tgz#83b9bfe0a3d589211ad13f6ac8524691817b7703"
integrity sha512-GmUZOcvD3ER3YaTnxkEnMToFH6Q8DpnbSM+7f+RZzDvKa/YLeiuU0gd+RWbyCxwA4mtWA/eJ9H+7HANjkjoqcA==

js-base64@^2.1.8:
version "2.5.1"
Expand Down