coject-hijri 1.1.0 → 1.4.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.
@@ -1,37 +1,12 @@
1
1
  import defaultHMoment, { Moment } from 'moment-hijri';
2
- import { AdapterMoment } from '../AdapterMoment';
3
- import { AdapterOptions, DateBuilderReturnType, FieldFormatTokenMap, MuiPickersAdapter } from '../models';
2
+ import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
3
+ import { AdapterOptions, DateBuilderReturnType, FieldFormatTokenMap, MuiPickersAdapter } from '@mui/x-date-pickers/models';
4
4
  declare module '@mui/x-date-pickers/models' {
5
5
  interface PickerValidDateLookup {
6
6
  'moment-hijri': Moment;
7
7
  }
8
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> {
9
+ export declare class Adapter extends AdapterMoment implements MuiPickersAdapter<Moment, string> {
35
10
  lib: string;
36
11
  moment: typeof defaultHMoment;
37
12
  isTimezoneCompatible: boolean;
@@ -1 +1 @@
1
- export { AdapterMomentHijri } from './AdapterMomentHijri';
1
+ export { Adapter } from './Adapter';
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Adapter = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _cojectHijri = _interopRequireDefault(require("../../coject-hijri"));
10
+ var _AdapterMoment = require("@mui/x-date-pickers/AdapterMoment");
11
+
12
+ const formatTokenMap = {
13
+ // Year
14
+ iY: {
15
+ sectionType: 'year',
16
+ contentType: 'letter'
17
+ },
18
+ iYY: {
19
+ sectionType: 'year',
20
+ contentType: 'letter'
21
+ },
22
+ iYYYY: {
23
+ sectionType: 'year',
24
+ contentType: 'letter'
25
+ },
26
+ // Month
27
+ iM: 'month',
28
+ iMM: 'month',
29
+ iMMM: {
30
+ sectionType: 'month',
31
+ contentType: 'letter'
32
+ },
33
+ iMMMM: {
34
+ sectionType: 'month',
35
+ contentType: 'letter'
36
+ },
37
+ // Day of the month
38
+ iD: {
39
+ sectionType: 'day',
40
+ contentType: 'digit',
41
+ maxLength: 2
42
+ },
43
+ iDD: 'day',
44
+ // Meridiem
45
+ A: 'meridiem',
46
+ a: 'meridiem',
47
+ // Hours
48
+ H: {
49
+ sectionType: 'hours',
50
+ contentType: 'digit',
51
+ maxLength: 2
52
+ },
53
+ HH: 'hours',
54
+ h: {
55
+ sectionType: 'hours',
56
+ contentType: 'digit',
57
+ maxLength: 2
58
+ },
59
+ hh: 'hours',
60
+ // Minutes
61
+ m: {
62
+ sectionType: 'minutes',
63
+ contentType: 'digit',
64
+ maxLength: 2
65
+ },
66
+ mm: 'minutes',
67
+ // Seconds
68
+ s: {
69
+ sectionType: 'seconds',
70
+ contentType: 'digit',
71
+ maxLength: 2
72
+ },
73
+ ss: 'seconds'
74
+ };
75
+ const defaultFormats = {
76
+ year: 'iYYYY',
77
+ month: 'iMMMM',
78
+ monthShort: 'iMMM',
79
+ dayOfMonth: 'iD',
80
+ dayOfMonthFull: 'iD',
81
+ weekday: 'dddd',
82
+ weekdayShort: 'ddd',
83
+ hours24h: 'HH',
84
+ hours12h: 'hh',
85
+ meridiem: 'A',
86
+ minutes: 'mm',
87
+ seconds: 'ss',
88
+ fullDate: 'iYYYY, iMMMM Do',
89
+ keyboardDateTime: 'iYYYY/iMM/iDD LT',
90
+ shortDate: 'iD iMMM',
91
+ normalDate: 'dddd, iD iMMM',
92
+ normalDateWithWeekday: 'DD iMMMM',
93
+ fullTime: 'LT',
94
+ fullTime12h: 'hh:mm A',
95
+ fullTime24h: 'HH:mm',
96
+ keyboardDate: 'iYYYY/iMM/iDD',
97
+ keyboardDateTime12h: 'iYYYY/iMM/iDD hh:mm A',
98
+ keyboardDateTime24h: 'iYYYY/iMM/iDD HH:mm'
99
+ };
100
+ const NUMBER_SYMBOL_MAP = {
101
+ '1': '١',
102
+ '2': '٢',
103
+ '3': '٣',
104
+ '4': '٤',
105
+ '5': '٥',
106
+ '6': '٦',
107
+ '7': '٧',
108
+ '8': '٨',
109
+ '9': '٩',
110
+ '0': '٠'
111
+ };
112
+ class Adapter extends _AdapterMoment.AdapterMoment {
113
+ constructor({
114
+ formats,
115
+ instance
116
+ } = {}) {
117
+ super({
118
+ locale: 'ar-SA',
119
+ instance
120
+ });
121
+ this.lib = 'coject-hijri';
122
+ this.moment = void 0;
123
+ this.isTimezoneCompatible = false;
124
+ this.formatTokenMap = formatTokenMap;
125
+ this.date = value => {
126
+ if (value === null) {
127
+ return null;
128
+ }
129
+ return this.moment(value).locale('ar-SA');
130
+ };
131
+ this.getTimezone = () => {
132
+ return 'default';
133
+ };
134
+ this.setTimezone = value => {
135
+ return value;
136
+ };
137
+ this.parse = (value, format) => {
138
+ if (value === '') {
139
+ return null;
140
+ }
141
+ return this.moment(value, format, true).locale('ar-SA');
142
+ };
143
+ this.formatNumber = numberToFormat => {
144
+ return numberToFormat.replace(/\d/g, match => NUMBER_SYMBOL_MAP[match]).replace(/,/g, '،');
145
+ };
146
+ this.startOfYear = value => {
147
+ return value.clone().startOf('iYear');
148
+ };
149
+ this.startOfMonth = value => {
150
+ return value.clone().startOf('iMonth');
151
+ };
152
+ this.endOfYear = value => {
153
+ return value.clone().endOf('iYear');
154
+ };
155
+ this.endOfMonth = value => {
156
+ return value.clone().endOf('iMonth');
157
+ };
158
+ this.addYears = (value, amount) => {
159
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'iYear') : value.clone().add(amount, 'iYear');
160
+ };
161
+ this.addMonths = (value, amount) => {
162
+ return amount < 0 ? value.clone().subtract(Math.abs(amount), 'iMonth') : value.clone().add(amount, 'iMonth');
163
+ };
164
+ this.getYear = value => {
165
+ return value.iYear();
166
+ };
167
+ this.getMonth = value => {
168
+ return value.iMonth();
169
+ };
170
+ this.getDate = value => {
171
+ return value.iDate();
172
+ };
173
+ this.setYear = (value, year) => {
174
+ return value.clone().iYear(year);
175
+ };
176
+ this.setMonth = (value, month) => {
177
+ return value.clone().iMonth(month);
178
+ };
179
+ this.setDate = (value, date) => {
180
+ return value.clone().iDate(date);
181
+ };
182
+ this.getWeekNumber = value => {
183
+ return value.iWeek();
184
+ };
185
+ this.getYearRange = ([start, end]) => {
186
+ if (start.isBefore('1937-03-14')) {
187
+ throw new Error('min date must be on or after 1356-01-01 H (1937-03-14)');
188
+ }
189
+ if (end.isAfter('2076-11-26')) {
190
+ throw new Error('max date must be on or before 1499-12-29 H (2076-11-26)');
191
+ }
192
+ return super.getYearRange([start, end]);
193
+ };
194
+ this.moment = instance || _cojectHijri.default;
195
+ this.locale = 'ar-SA';
196
+ this.formats = (0, _extends2.default)({}, defaultFormats, formats);
197
+ }
198
+ }
199
+ exports.Adapter = Adapter;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Adapter", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Adapter.Adapter;
10
+ }
11
+ });
12
+ var _Adapter = require("./Adapter");
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "module": "./index.js",
4
- "main": "../node/AdapterMomentHijri/index.js",
4
+ "main": "./node/index.js",
5
5
  "types": "./index.d.ts"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coject-hijri",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "description": "A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js.",
5
5
  "author": "Akwad",
6
6
  "license": "MIT",