3.0.0 • Published 4 years ago

ng-jalali-date-time v3.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
4 years ago

ng-jalali-date-time

Jalali date / month / range picker for Angular with Material Design support

This library uses Angular 10


Table of contents

Installation

# Create new Angular Application
ng new my-application

# Go to application directory
cd my-application

# Add Material support to your application
# Choose YES when you asked for setting up "browser animations for Angular Material"
ng add @angular/material

# Install ng-jalali-date-time and it dependencies, using NPM
npm install --save jalali-date-time ng-jalali-date-time

Usage

import NgJalaliDateTimeModule

import { NgJalaliDateTimeModule } from 'ng-jalali-date-time';

@NgModule({
    ...
    imports: [
        ...
        NgJalaliDateTimeModule
    ],
    ...
})

jalali-date-time Directive

alt text

<span jalali-date-time></span>

Properties

NameTypeDescription
formFormGroupComponents FormGroup (Reactive Forms)
namestringForm object name (Reactive Forms)
appearancestringForm object appearance (legacy, standard, fill, outline)
configNgJalaliDateTimeConfigInterfaceObject configurations
cssNgJalaliDateTimeCssInterfaceObject css styles
datestringDefault date value
timestringDefault time value
labelstringmat-form-field label

Events

Nametype
changedNgJalaliDateTimeValueInterface

Sample

# component.ts

import {
    NgJalaliDateTimeConfigInterface,
    NgJalaliDateTimeCssInterface,
    NgJalaliDateTimeValueInterface
} from 'ng-jalali-date-time';

export class MyComponent implements OnInit {
    public form: FormGroup
    public name: string = 'date';

    public config: NgJalaliDateTimeConfigInterface = {
        required: true,
        min: '1300-01-01',
        max: '1400-01-01',
        reset: true,
        error: 'مشخص کردن مقدار الزامی است',
        time: true,
        second: false
    };

    public css: NgJalaliDateTimeCssInterface = {
        font: 'yekan'
    };

    public date: string = '';
    public time: string = '';
    public label: string = 'انتخاب تاریخ';

    ngOnInit() {
        this.form = new FormGroup({})
    }

    dateChanged(value: NgJalaliDateTimeValueInterface) {
        console.log(value);
    }
}
# component.html
<span
    jalali-date-time
    [form]="form"
    [name]="name"
    [config]="config"
    [css]="css"
    [date]="date"
    [time]="time"
    [label]="label"
    (changed)="dateChanged($event)"
>
</span>

jalali-month Directive

alt text

<span jalali-month></span>

Properties

NameTypeDescription
formFormGroupComponents FormGroup (Reactive Forms)
namestringForm object name (Reactive Forms)
appearancestringForm object appearance (legacy, standard, fill, outline)
configNgJalaliDateTimeConfigInterfaceObject configurations
cssNgJalaliDateTimeCssInterfaceObject css styles
monthstringDefault month value
labelstringmat-form-field label

Events

Nametype
changedNgJalaliMonthValueInterface

Sample

# component.ts

import {
    NgJalaliDateTimeConfigInterface,
    NgJalaliDateTimeCssInterface,
    NgJalaliMonthValueInterface
} from 'ng-jalali-date-time';

export class MyComponent implements OnInit {
    public form: FormGroup
    public name: string = 'date';

    public config: NgJalaliDateTimeConfigInterface = {
        required: true,
        min: '1300-01',
        max: '1400-01',
        reset: true,
        error: 'مشخص کردن مقدار الزامی است'
    };

    public css: NgJalaliDateTimeCssInterface = {
        font: 'yekan'
    };

    public month: string = '';
    public label: string = 'انتخاب ماه';

    ngOnInit() {
        this.form = new FormGroup({})
    }

    dateChanged(value: NgJalaliMonthValueInterface) {
        console.log(value);
    }
}
# component.html
<span
    jalali-month
    [form]="form"
    [name]="name"
    [config]="config"
    [css]="css"
    [month]="month"
    [label]="label"
    (changed)="dateChanged($event)"
>
</span>

jalali-range Directive

alt text

<span jalali-range></span>

Properties

NameTypeDescription
formFormGroupComponents FormGroup (Reactive Forms)
namestringForm object name (Reactive Forms)
appearancestringForm object appearance (legacy, standard, fill, outline)
configNgJalaliDateTimeConfigInterfaceObject configurations
cssNgJalaliDateTimeCssInterfaceObject css styles
fromstringDefault range's first date (from) value
tostringDefault range's last date (to) value
labelstringmat-form-field label

Events

Nametype
changedNgJalaliRangeValueInterface

Sample

# component.ts

import {
    NgJalaliDateTimeConfigInterface,
    NgJalaliDateTimeCssInterface,
    NgJalaliRangeValueInterface
} from 'ng-jalali-date-time';

export class MyComponent implements OnInit {
    public form: FormGroup
    public name: string = 'date';

    public config: NgJalaliDateTimeConfigInterface = {
        required: true,
        min: '1300-01-01',
        max: '1400-01-01',
        reset: true,
        error: 'مشخص کردن مقدار الزامی است'
    };

    public css: NgJalaliDateTimeCssInterface = {
        font: 'yekan'
    };

    public from: string = '';
    public to: string = '';
    public label: string = 'انتخاب دوره زمانی';

    ngOnInit() {
        this.form = new FormGroup({})
    }

    dateChanged(value: NgJalaliRangeValueInterface) {
        console.log(value);
    }
}
# component.html
<span
    jalali-date-time
    [form]="form"
    [name]="name"
    [config]="config"
    [css]="css"
    [from]="from"
    [to]="to"
    [label]="label"
    (changed)="dateChanged($event)"
>
</span>

Interfaces

NgJalaliDateTimeConfigInterface

NameTypeDescription
requiredbooleanSet object as required on Reactive Forms
minstringMinimum acceptable date value
maxstringMaximum acceptable date value
resetbooleanShow reset button if date is selected
errorstringError message (Required object)
timebooleanShow time selector
secondbooleanActive second selector (if time value is true)

NgJalaliDateTimeCssInterface

NameTypeDescription
fontstringFont family name
fieldNgStyle objectmat-form-field CSS style
inputNgStyle objectInput CSS style
resetNgStyle objectReset button CSS style
boxNgStyle objectCalendar box CSS style
arrowNgStyle objectFirst/Previous/Next/Last arrows CSS style
headerNgStyle objectCalendar header (month/year title) CSS style
itemNgStyle objectCalendar date/month items CSS style
selectedNgStyle objectSelected date/month item CSS style
currentNgStyle objectCurrent date/month item CSS style
dateobjectjalali-date-time Directive CSS styles
rangeobjectjalali-range Directive CSS styles

jalali-date-time Directive CSS styles

NameTypeDescription
nameNgStyle objectDay names CSS style
timeNgStyle objectTime selectors (inputs) CSS style

jalali-range Directive CSS styles

NameTypeDescription
toolNgStyle objectSelector tools CSS style
customNgStyle objectCustom range selector CSS style
confirmNgStyle objectConfirm selector CSS style
nameNgStyle objectDay names CSS style
dateNgStyle objectCustom date title CSS style

NgJalaliDateTimeValueInterface

NameType
jalalistring
gregorianstring
dateDate
timestring
timestampnumber

Sample

{
    "jalali": "1398-07-27",
    "gregorian": "2019-10-19",
    "date": "2019-10-19T09:04:00.000Z",
    "time": "12:34:00",
    "timestamp": 1571475840
}

NgJalaliMonthValueInterface

NameType
monthstring
daysnumber
gregorianObject
gregorian .firststring
gregorian .laststring

Sample

{
    "month": "1398-07",
    "days": 30,
    "gregorian": {
        "first": "2019-09-23",
        "last": "2019-10-22"
    }
}

NgJalaliRangeValueInterface

NameType
rangestring
fromstring
tostring
daysnumber
hoursnumber
minutesnumber
secondsnumber
gregorianObject
gregorian .fromstring
gregorian .tostring

Sample

{
    "range": "1398-07-01|1398-07-30",
    "from": "1398-07-01",
    "to": "1398-07-30",
    "days": 30,
    "hours": 720,
    "minutes": 43200,
    "seconds": 2592000,
    "gregorian": {
        "from": "2019-09-23",
        "to": "2019-10-22"
    }
}

Pipes

PipeSampleResult
jalaliDate (date)'1398-07-27' | jalaliDateSat Oct 19 2019 00:00:00 GMT+0330 (Iran Standard Time)
jalaliDate (date/time)'1398-07-27 16:52:23' | jalaliDateSat Oct 19 2019 16:52:23 GMT+0330 (Iran Standard Time)
jalaliMonth'1398-07' | jalaliMonthمهر ۱۳۹۸
jalaliRange'1398-07-01|1398-07-30' | jalaliRange۱ تا ۳۰ مهر ۱۳۹۸
jalaliFull (string)'1398-07-27 16:52:23' | jalaliFullشنبه، ۲۷ مهر ۱۳۹۸ ۱۶:۵۲:۲۳
jalaliFull (timestamp)1571491343 | jalaliFullشنبه، ۲۷ مهر ۱۳۹۸ ۱۶:۵۲:۲۳
jalaliTitle (string)'1398-07-27' | jalaliTitleشنبه، ۲۷ مهر ۱۳۹۸
jalaliTitle (timestamp)1571491343 | jalaliTitleشنبه، ۲۷ مهر ۱۳۹۸
jalaliTimestamp (date)'1398-07-27' | jalaliTimestamp1571430600
jalaliTimestamp (date/time)'1398-07-27 16:52:23' | jalaliTimestamp1571491343
jalaliDays (range)'1398-07-01|1398-07-30' | jalaliDays30
jalaliDays (date)'1398-07-27' | jalaliDays1
3.0.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago