1.0.8 • Published 7 months ago

angular-hijri-gregorian-datepicker v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Angular Hijri Gregorian Calendar(Datepicker)

Build Dependencies License

  • Most accurate Hijri, Gregorian calendar(date-picker) on NPM with 100% accuracy percentage.
  • Robust and tested code angular hijri/gregorian calendar/date-picker component for Angular 10 - 16, 17+ projects.
  • Ionic 3 - 4, 5, 6 + is supported, can be used in iOS and Android.
  • Zero dependents package.

Dependents

Angular hijri gregorian with Zero dependents that supports conversion between Gregorian and Hijri calendars.

Preview

Background

The Umm Al-Qura calendar is the lunar Hijri calendar officially adopted by Saudi Arabia for administrative purposes. It was originated from Umm Al-Qura newspaper, the official newspaper of government of Saudi Arabia. The newspaper is published weekly and its first issue was on Friday, 15 Jumada al-Ula 1343 AH (12 December 1924 CE). However, the calendar has been printed and distributed separately by the Saudi government since 1346 AH (1927 CE).

The calendar is widely used in Saudi Arabia, especially by the public sector. Official documents, political letters, health care records, and education certificates, are just examples of many other documents that are dated by the Hijri calendar.

However, the Gregorian calendar is the calendar used in most of the world, and it has been implemented as the default calendar in nearly every computer and database.

Examples/Demo

Online demo can be found:

Stackblitz

Github Pages

Star it to inspire us to build the best component!

Features

  • Can be used as a calendar or a datepicker.
  • RTL and LTR support
  • Easy to switch between Gregorian and Hijri calendars.
  • Ability to specify the default calendar type either Gregorian or Hijri.
  • Converting dates when changing type of calendar.
  • Ability to specify min and max value for Gregorian and Hijri.
  • Ability to make it required or readonly.
  • Very easy to customize.
  • Can select Multiple dates.
  • Event listeners for all datepicker events.
  • Can customize future and past years number.
  • Responsive desing for web and mobile.

Supported platforms

Angular 10 - 16, 17 + Ionic 3 - 4, 5, 6 + Mobile browsers and WebViews on: Android and iOS Desktop browsers: Chrome, Firefox, Safari, Edge v.79 + Other browsers: Edge v.41 - 44 (without code hidden feature)

Installation

$ npm install angular-hijri-gregorian-datepicker

Usage

Import HijriGregorianDatepickerModule in your app module or page module:

import { HijriGregorianDatepickerModule } from 'angular-hijri-gregorian-datepicker';

@NgModule({
  imports: [
    // ...
    HijriGregorianDatepickerModule
  ]
})
<hijri-gregorian-datepicker
  [canChangeMode]="true"
  [todaysDateSection]="true"
  [futureValidation]="true"
  [disableYearPicker]="false"
  [disableMonthPicker]="false"
  [disableDayPicker]="false"
  [multiple]="true"
  [isRequired]="false"
  [showConfirmButton]="true"
  [markToday]="true"
  [mode]="'greg'"
  [dir]="'ltr'"
  [locale]="'en'"
  [submitTextButton]="'Confirm'"
  [todaysDateText]="'Today\'s Date'"
  [ummAlQuraDateText]="'التاريخ الهجرى'"
  [yearSelectLabel]="'Year'"
  [monthSelectLabel]="'Month'"
  [futureValidationMessageEn]="'Selected date cannot be in the future!'"
  [futureValidationMessageAr]="
    'التاريخ المحدد لا يمكن ان يكون في المستقبل!'
    "
  [pastYearsLimit]="90"
  [futureYearsLimit]="0"
  [styles]="stylesConfig"
  (onSubmit)="onSubmit($event)"
  (onDaySelect)="onChange($event)"
  (onMonthChange)="onMonthChangeTest($event)"
  (onYearChange)="onYearChangeTest($event)"
></hijri-gregorian-datepicker>

Inside your component.ts:

  // this called every time when user confirms a selected date
    onSubmitEvent(code: string) {
    }

    // this called only every time the use selects a date
    onChangeEvent(code: string) {
    }

    // this called every time the month value channges
    onMonthChangeEvent(code: string) {
    }

    // this called every time the year value channges
    onYearChangeEvent(code: string) {
    }

@Inputs()

PropertyTypeDefaultDescription
canChangeModebooleantrueWhen true the user can toggle calendar modes, if false the user has only one calendar mode
todaysDateSectionbooleantrueWhen true the section with current today date will be shown, if false it will be hidden
futureValidationbooleantrueWhen true the user cannot choose any future dates, if false user can select future dates
disableYearPickerbooleanfalseWhen true the user cannot select different years, if false year select will be enabled
disableMonthPickerbooleanfalseWhen true the user cannot select different months, if false month select will be enabled
disableDayPickerbooleanfalseWhen true the user cannot select days, if false days select will be enabled
multiplebooleanfalseWhen true the user can select multiple days, if false only one date can be selected
isRequiredbooleantrueWhen true the confirm button will be disabled until user selects a date, if false the button will be enabled
showConfirmButtonbooleantrueWhen true the confirm button will be displayed, if false it will be hidden
markTodaybooleantrueWhen true today date will be marked(bordered), if false it will not be marked
modestringgregCalendar mode, either ummAlQura or greg
dirstringltrLayout direction, either ltr or rtl
localestringenThe language of the calendar layout, either ar or en
submitTextButtonstringConfirmConfirm button text value
todaysDateTextstringTodays\'s DateToday's date text in todaysDateSection
ummAlQuraDateTextstringالتاريخ الهجرىText next to checkbox to toggle date todaysDateSection
yearSelectLabelstringYearLabel of the year select option
monthSelectLabelstringMonthLabel of the month select option
futureValidationMessageEnstringSelected date cannot be in the future!English future validation message if futureValidation is set to true
futureValidationMessageArstringالتاريخ المحدد لا يمكن ان يكون في المستقبل!Arabic future validation message if futureValidation is set to true
pastYearsLimitnumber90indicates for the past years number you want to allow user to select from
futureYearsLimitnumber0indicates for the future years number you want to allow user to select from
stylesobject{}Styles for the calendar look and feel

Styles

PropertyTypeDefaultDescription
backgroundColorstring#E3F6F5Background of the calendar
primaryColorstring#272343Color of the today's date, year and month texts
secondaryColorstring#272343Background of submit button and selected days in calendar
todaysDateBgColorstring#272343Background of "today's date" date section
todaysDateTextColorstring#fffColor of "today's date" date section text
confirmBtnTextColorstring#fffColor of "Confirm" button text
disabledDayColorstring#C0C0C0Disabled days text color
dayNameColorstring#0d7f91Day names text color
dayColorstring#000Enabled days text color
fontFamilystringDefault-RegularFont family of the font used globally and pre defined within project

@Outputs()

OutputDescription
onSubmitWill be called every time when a user submits a selected date
onDaySelectWill be called every time when a user selects new date
onMonthChangeWill be called every time the month value changes
onYearChangeWill be called every time the year value changes

Helper Functions

import { HijriGregorianDatepickerService } from 'angular-hijri-gregorian-datepicker';

  constructor(private calendarService: HijriGregorianDatepickerService) {

  }
OutputDescription
convertDateConverts dates from Gregorian to Umm Al Qura and vice versa
checkPastOrFutureChecks date whether it's future or past date('Future', 'Past', 'Today')
formatDateConverts date from human-readable string representation(ex. Mon Sep 05 2023 15:30:45 GMT+0200) to separated "/" string(ex. 05/09/2023)
parseDateThe opposite of formateDate function
getGregorianMonthDataGenerates an array of objects of Gregorian month passed to it
getUmAlQurraMonthDataGenerates an array of objects of Umm Al Qura month passed to it

Contributing

Contributions are more than welcome!

License

MIT License

Copyright (c) 2022 Muhammad Hanafi, Imad Khan