coject-hijri 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ import defaultHMoment, { Moment } from 'moment-hijri';
2
+ import { AdapterMoment } from '../AdapterMoment';
3
+ import { AdapterOptions, DateBuilderReturnType, FieldFormatTokenMap, MuiPickersAdapter } from '../models';
4
+ declare module '@mui/x-date-pickers/models' {
5
+ interface PickerValidDateLookup {
6
+ 'moment-hijri': Moment;
7
+ }
8
+ }
9
+ /**
10
+ * Based on `@date-io/hijri`
11
+ *
12
+ * MIT License
13
+ *
14
+ * Copyright (c) 2017 Dmitriy Kovalenko
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ * of this software and associated documentation files (the "Software"), to deal
18
+ * in the Software without restriction, including without limitation the rights
19
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ * copies of the Software, and to permit persons to whom the Software is
21
+ * furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all
24
+ * copies or substantial portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ * SOFTWARE.
33
+ */
34
+ export declare class AdapterMomentHijri extends AdapterMoment implements MuiPickersAdapter<Moment, string> {
35
+ lib: string;
36
+ moment: typeof defaultHMoment;
37
+ isTimezoneCompatible: boolean;
38
+ formatTokenMap: FieldFormatTokenMap;
39
+ constructor({ formats, instance }?: AdapterOptions<string, typeof defaultHMoment>);
40
+ date: <T extends string | null | undefined>(value?: T | undefined) => DateBuilderReturnType<T, defaultHMoment.Moment>;
41
+ getTimezone: () => string;
42
+ setTimezone: (value: Moment) => Moment;
43
+ parse: (value: string, format: string) => defaultHMoment.Moment | null;
44
+ formatNumber: (numberToFormat: string) => string;
45
+ startOfYear: (value: Moment) => defaultHMoment.Moment;
46
+ startOfMonth: (value: Moment) => defaultHMoment.Moment;
47
+ endOfYear: (value: Moment) => defaultHMoment.Moment;
48
+ endOfMonth: (value: Moment) => defaultHMoment.Moment;
49
+ addYears: (value: Moment, amount: number) => defaultHMoment.Moment;
50
+ addMonths: (value: Moment, amount: number) => defaultHMoment.Moment;
51
+ getYear: (value: Moment) => number;
52
+ getMonth: (value: Moment) => number;
53
+ getDate: (value: Moment) => number;
54
+ setYear: (value: Moment, year: number) => defaultHMoment.Moment;
55
+ setMonth: (value: Moment, month: number) => defaultHMoment.Moment;
56
+ setDate: (value: Moment, date: number) => defaultHMoment.Moment;
57
+ getWeekNumber: (value: Moment) => number;
58
+ getYearRange: ([start, end]: [Moment, Moment]) => defaultHMoment.Moment[];
59
+ }
@@ -0,0 +1,190 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import defaultHMoment from '../coject-hijri';
3
+ import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
4
+ const formatTokenMap = {
5
+ // Year
6
+ iY: {
7
+ sectionType: 'year',
8
+ contentType: 'letter'
9
+ },
10
+ iYY: {
11
+ sectionType: 'year',
12
+ contentType: 'letter'
13
+ },
14
+ iYYYY: {
15
+ sectionType: 'year',
16
+ contentType: 'letter'
17
+ },
18
+ // Month
19
+ iM: 'month',
20
+ iMM: 'month',
21
+ iMMM: {
22
+ sectionType: 'month',
23
+ contentType: 'letter'
24
+ },
25
+ iMMMM: {
26
+ sectionType: 'month',
27
+ contentType: 'letter'
28
+ },
29
+ // Day of the month
30
+ iD: {
31
+ sectionType: 'day',
32
+ contentType: 'digit',
33
+ maxLength: 2
34
+ },
35
+ iDD: 'day',
36
+ // Meridiem
37
+ A: 'meridiem',
38
+ a: 'meridiem',
39
+ // Hours
40
+ H: {
41
+ sectionType: 'hours',
42
+ contentType: 'digit',
43
+ maxLength: 2
44
+ },
45
+ HH: 'hours',
46
+ h: {
47
+ sectionType: 'hours',
48
+ contentType: 'digit',
49
+ maxLength: 2
50
+ },
51
+ hh: 'hours',
52
+ // Minutes
53
+ m: {
54
+ sectionType: 'minutes',
55
+ contentType: 'digit',
56
+ maxLength: 2
57
+ },
58
+ mm: 'minutes',
59
+ // Seconds
60
+ s: {
61
+ sectionType: 'seconds',
62
+ contentType: 'digit',
63
+ maxLength: 2
64
+ },
65
+ ss: 'seconds'
66
+ };
67
+ const defaultFormats = {
68
+ year: 'iYYYY',
69
+ month: 'iMMMM',
70
+ monthShort: 'iMMM',
71
+ dayOfMonth: 'iD',
72
+ dayOfMonthFull: 'iD',
73
+ weekday: 'dddd',
74
+ weekdayShort: 'ddd',
75
+ hours24h: 'HH',
76
+ hours12h: 'hh',
77
+ meridiem: 'A',
78
+ minutes: 'mm',
79
+ seconds: 'ss',
80
+ fullDate: 'iYYYY, iMMMM Do',
81
+ keyboardDateTime: 'iYYYY/iMM/iDD LT',
82
+ shortDate: 'iD iMMM',
83
+ normalDate: 'dddd, iD iMMM',
84
+ normalDateWithWeekday: 'DD iMMMM',
85
+ fullTime: 'LT',
86
+ fullTime12h: 'hh:mm A',
87
+ fullTime24h: 'HH:mm',
88
+ keyboardDate: 'iYYYY/iMM/iDD',
89
+ keyboardDateTime12h: 'iYYYY/iMM/iDD hh:mm A',
90
+ keyboardDateTime24h: 'iYYYY/iMM/iDD HH:mm'
91
+ };
92
+ const NUMBER_SYMBOL_MAP = {
93
+ '1': '١',
94
+ '2': '٢',
95
+ '3': '٣',
96
+ '4': '٤',
97
+ '5': '٥',
98
+ '6': '٦',
99
+ '7': '٧',
100
+ '8': '٨',
101
+ '9': '٩',
102
+ '0': '٠'
103
+ };
104
+ export class Adapter extends AdapterMoment {
105
+ constructor({
106
+ formats,
107
+ instance
108
+ } = {}) {
109
+ super({
110
+ locale: 'ar-SA',
111
+ instance
112
+ });
113
+ this.lib = 'coject-hijri';
114
+ this.moment = void 0;
115
+ this.isTimezoneCompatible = false;
116
+ this.formatTokenMap = formatTokenMap;
117
+ this.date = value => {
118
+ if (value === null) {
119
+ return null;
120
+ }
121
+ return this.moment(value).locale('ar-SA');
122
+ };
123
+ this.getTimezone = () => {
124
+ return 'default';
125
+ };
126
+ this.setTimezone = value => {
127
+ return value;
128
+ };
129
+ this.parse = (value, format) => {
130
+ if (value === '') {
131
+ return null;
132
+ }
133
+ return this.moment(value, format, true).locale('ar-SA');
134
+ };
135
+ this.formatNumber = numberToFormat => {
136
+ return numberToFormat.replace(/\d/g, match => NUMBER_SYMBOL_MAP[match]).replace(/,/g, '،');
137
+ };
138
+ this.startOfYear = value => {
139
+ return value.clone().startOf('iYear');
140
+ };
141
+ this.startOfMonth = value => {
142
+ return value.clone().startOf('iMonth');
143
+ };
144
+ this.endOfYear = value => {
145
+ return value.clone().endOf('iYear');
146
+ };
147
+ this.endOfMonth = value => {
148
+ return value.clone().endOf('iMonth');
149
+ };
150
+ this.addYears = (value, amount) => {
151
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'iYear') : value.clone().add(amount, 'iYear');
152
+ };
153
+ this.addMonths = (value, amount) => {
154
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'iMonth') : value.clone().add(amount, 'iMonth');
155
+ };
156
+ this.getYear = value => {
157
+ return value.iYear();
158
+ };
159
+ this.getMonth = value => {
160
+ return value.iMonth();
161
+ };
162
+ this.getDate = value => {
163
+ return value.iDate();
164
+ };
165
+ this.setYear = (value, year) => {
166
+ return value.clone().iYear(year);
167
+ };
168
+ this.setMonth = (value, month) => {
169
+ return value.clone().iMonth(month);
170
+ };
171
+ this.setDate = (value, date) => {
172
+ return value.clone().iDate(date);
173
+ };
174
+ this.getWeekNumber = value => {
175
+ return value.iWeek();
176
+ };
177
+ this.getYearRange = ([start, end]) => {
178
+ if (start.isBefore('1937-03-14')) {
179
+ throw new Error('min date must be on or after 1356-01-01 H (1937-03-14)');
180
+ }
181
+ if (end.isAfter('2076-11-26')) {
182
+ throw new Error('max date must be on or before 1499-12-29 H (2076-11-26)');
183
+ }
184
+ return super.getYearRange([start, end]);
185
+ };
186
+ this.moment = instance || defaultHMoment;
187
+ this.locale = 'ar-SA';
188
+ this.formats = _extends({}, defaultFormats, formats);
189
+ }
190
+ }
@@ -0,0 +1 @@
1
+ export { AdapterMomentHijri } from './AdapterMomentHijri';
@@ -0,0 +1 @@
1
+ export { Adapter } from './adapter';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/AdapterMomentHijri/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ declare module 'coject-hijri';
package/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "coject-hijri",
3
+ "version": "1.1.0",
3
4
  "description": "A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js.",
4
5
  "author": "Akwad",
5
6
  "license": "MIT",
@@ -23,7 +24,6 @@
23
24
  "dependencies": {
24
25
  "moment": "^2.30.0"
25
26
  },
26
- "version": "1.0.0",
27
27
  "scripts": {
28
28
  "test": "echo \"Error: no test specified\" && exit 1"
29
29
  },