@acorex/core 5.0.44 → 5.0.47

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.
@@ -164,14 +164,43 @@ AXConfig.dataChangeSubject = new Subject();
164
164
  // @dynamic
165
165
  class AXDateTime {
166
166
  constructor(value = new Date(), calendar = AXConfig.get(`dateTime.calendar`)) {
167
- this._calendar =
168
- typeof calendar == 'string'
169
- ? AXConfig.get(`dateTime.calendars.${calendar}`)
170
- : calendar;
167
+ this._formatKeys = {
168
+ ss: () => this.pad(this.date.getSeconds(), 2),
169
+ s: () => this.date.getSeconds().toString(),
170
+ //
171
+ dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
172
+ d: () => this.calendar.dayOfMonth(this.date).toString(),
173
+ //
174
+ mm: () => this.pad(this.date.getMinutes(), 2),
175
+ m: () => this.date.getMinutes().toString(),
176
+ //
177
+ MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
178
+ MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
179
+ MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
180
+ //
181
+ DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
182
+ DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
183
+ //
184
+ yyyy: () => this.calendar.year(this.date).toString(),
185
+ YYYY: () => this.calendar.year(this.date).toString(),
186
+ yy: () => this.calendar.year(this.date).toString().substring(2),
187
+ YY: () => this.calendar.year(this.date).toString().substring(2),
188
+ //
189
+ HH: () => this.pad(this.date.getHours(), 2),
190
+ H: () => this.date.getHours().toString(),
191
+ //
192
+ hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
193
+ h: () => (this.date.getHours() % 12 || 12).toString(),
194
+ //
195
+ A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
196
+ a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
197
+ };
198
+ this._calendar = AXDateTime.resolveCalendar(calendar);
171
199
  if (value instanceof Date) {
172
200
  this._date = value;
173
201
  }
174
202
  else {
203
+ //TODO: parse jalali
175
204
  this._date = new Date(value);
176
205
  }
177
206
  }
@@ -188,6 +217,31 @@ class AXDateTime {
188
217
  }
189
218
  return date;
190
219
  }
220
+ static from(value = {
221
+ calendar: AXConfig.get('dateTime.calendar'),
222
+ year: 1,
223
+ month: 1,
224
+ date: 1,
225
+ hours: 0,
226
+ minutes: 0,
227
+ seconds: 0,
228
+ ms: 0
229
+ }) {
230
+ // let date: AXDateTime = new AXDateTime(new Date(), value.calendar);
231
+ // date.set('year', value.year);
232
+ // date.set('month', value.month);
233
+ // date.set('day', value.date);
234
+ // date.set('hour', value.hours);
235
+ // date.set('minute', value.minutes);
236
+ // date.set('second', value.seconds);
237
+ // date.set('ms', value.ms);
238
+ return AXDateTime.resolveCalendar(value.calendar).create(value);
239
+ }
240
+ static resolveCalendar(calendar) {
241
+ return typeof calendar == 'string'
242
+ ? AXConfig.get(`dateTime.calendars.${calendar}`)
243
+ : calendar;
244
+ }
191
245
  get date() {
192
246
  return this._date;
193
247
  }
@@ -195,7 +249,7 @@ class AXDateTime {
195
249
  return this._calendar;
196
250
  }
197
251
  clone() {
198
- return new AXDateTime(this.date, this.calendar.name());
252
+ return new AXDateTime(this.date, this.calendar);
199
253
  }
200
254
  get dayOfMonth() {
201
255
  return this._calendar.dayOfMonth(this.date);
@@ -244,40 +298,9 @@ class AXDateTime {
244
298
  return this._calendar.endOf(this.date, unit);
245
299
  }
246
300
  format(format = AXConfig.get('dateTime.shortDateFormat')) {
247
- const keys = {
248
- ss: () => this.pad(this.date.getSeconds(), 2),
249
- s: () => this.date.getSeconds().toString(),
250
- //
251
- dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
252
- d: () => this.calendar.dayOfMonth(this.date).toString(),
253
- //
254
- mm: () => this.pad(this.date.getMinutes(), 2),
255
- m: () => this.date.getMinutes().toString(),
256
- //
257
- MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
258
- MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
259
- MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
260
- //
261
- DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
262
- DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
263
- //
264
- yyyy: () => this.calendar.year(this.date).toString(),
265
- YYYY: () => this.calendar.year(this.date).toString(),
266
- yy: () => this.calendar.year(this.date).toString().substring(2),
267
- YY: () => this.calendar.year(this.date).toString().substring(2),
268
- //
269
- HH: () => this.pad(this.date.getHours(), 2),
270
- H: () => this.date.getHours().toString(),
271
- //
272
- hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
273
- h: () => (this.date.getHours() % 12 || 12).toString(),
274
- //
275
- A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
276
- a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
277
- };
278
- const re = new RegExp(_.orderBy(Object.keys(keys), c => c.length, ['desc']).join("|"), "gi");
279
- return format.replace(re, function (matched) {
280
- return keys[matched]();
301
+ const re = new RegExp(_.orderBy(Object.keys(this._formatKeys), c => c.length, ['desc']).join("|"), "gi");
302
+ return format.replace(re, (matched) => {
303
+ return this._formatKeys[matched]();
281
304
  });
282
305
  }
283
306
  pad(n, width, z = '0') {
@@ -291,7 +314,7 @@ class AXDateTime {
291
314
  return this.compare(value, unit) == 0;
292
315
  }
293
316
  compare(value, unit = 'day') {
294
- const val = AXDateTime.convert(value);
317
+ const val = AXDateTime.convert(value, this.calendar.name());
295
318
  const func = (v1, v2) => {
296
319
  if (v1 == v2) {
297
320
  return 0;
@@ -476,6 +499,9 @@ class GeorgianCalendar {
476
499
  "Thu", "Fri", "Sat"
477
500
  ];
478
501
  }
502
+ create(value) {
503
+ return new AXDateTime(new Date(value.year, value.month - 1, value.date, value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
504
+ }
479
505
  name() {
480
506
  return 'gregorian';
481
507
  }
@@ -645,6 +671,10 @@ class JalaliCalendar {
645
671
  this.dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
646
672
  this.dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
647
673
  }
674
+ create(value) {
675
+ const a = this.toGregorian(value.year, value.month, value.date);
676
+ return new AXDateTime(new Date(a.getFullYear(), a.getMonth(), a.getDate(), value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
677
+ }
648
678
  name() {
649
679
  return 'jalali';
650
680
  }
@@ -687,14 +717,10 @@ class JalaliCalendar {
687
717
  let jd = this.dayOfMonth(date);
688
718
  let jm = this.monthOfYear(date);
689
719
  let jy = this.year(date);
690
- jm = (jm + amount) % 12;
691
- if (0 > jm) {
692
- jy += (this.monthOfYear(date) + amount - jm - 12) / 12;
693
- jm += 12;
694
- }
695
- else {
696
- jy += ((this.monthOfYear(date) + amount - jm) / 12);
697
- }
720
+ const nm = (jm + amount);
721
+ const ny = (nm % 12) ? Math.floor(nm / 12) : 0;
722
+ jy += ny;
723
+ jm = nm - (ny * 12);
698
724
  const vv = this.toGregorian(jy, jm, jd);
699
725
  v.setFullYear(vv.getFullYear());
700
726
  v.setMonth(vv.getMonth());
@@ -707,6 +733,10 @@ class JalaliCalendar {
707
733
  break;
708
734
  case 'year':
709
735
  {
736
+ // const v = new Date(value);
737
+ // v.setFullYear(v.getFullYear() + amount);
738
+ // value = v.valueOf();
739
+ // break
710
740
  const v = new Date(value);
711
741
  let jd = this.dayOfMonth(date);
712
742
  let jm = this.monthOfYear(date);
@@ -716,8 +746,8 @@ class JalaliCalendar {
716
746
  v.setMonth(vv.getMonth());
717
747
  v.setDate(vv.getDate());
718
748
  value = v.valueOf();
749
+ break;
719
750
  }
720
- break;
721
751
  case 'day':
722
752
  default:
723
753
  value += 86400000 * amount;
@@ -725,7 +755,35 @@ class JalaliCalendar {
725
755
  return new AXDateTime(new Date(value), this.name());
726
756
  }
727
757
  set(date, unit, value) {
728
- throw new Error("Method not implemented.");
758
+ const clone = new Date(date.valueOf());
759
+ const jDate = this.toJalali(clone);
760
+ switch (unit) {
761
+ case 'second':
762
+ clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
763
+ break;
764
+ case 'minute':
765
+ clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
766
+ break;
767
+ case 'hour':
768
+ clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
769
+ break;
770
+ default:
771
+ case 'day':
772
+ const gDate = this.toGregorian(jDate.year, jDate.month, value);
773
+ clone.setDate(gDate.getDate());
774
+ break;
775
+ case "week":
776
+ break;
777
+ case "month":
778
+ const gDate2 = this.toGregorian(jDate.year, value, jDate.day);
779
+ clone.setMonth(gDate2.getMonth());
780
+ break;
781
+ case "year":
782
+ const gDate3 = this.toGregorian(value, jDate.month, jDate.day);
783
+ clone.setFullYear(gDate3.getFullYear());
784
+ break;
785
+ }
786
+ return new AXDateTime(clone, this.name());
729
787
  }
730
788
  startOf(date, unit) {
731
789
  const clone = new Date(date.valueOf());
@@ -973,7 +1031,7 @@ class AXDateTimeModule {
973
1031
  gregorian: new GeorgianCalendar()
974
1032
  },
975
1033
  calendar: 'gregorian',
976
- shortDateFormat: 'DDD, dd MMM yyyy'
1034
+ shortDateFormat: 'DDDD, d MMM yyyy'
977
1035
  }
978
1036
  });
979
1037
  }
@@ -1187,6 +1245,8 @@ class AXPlatform {
1187
1245
  nativeEvent: e,
1188
1246
  source: this
1189
1247
  });
1248
+ //
1249
+ this._setFullHeightRatio();
1190
1250
  });
1191
1251
  document.addEventListener('click', (e) => {
1192
1252
  this.click.next({
@@ -1200,6 +1260,8 @@ class AXPlatform {
1200
1260
  source: this
1201
1261
  });
1202
1262
  }, true);
1263
+ // init functions
1264
+ this._setFullHeightRatio();
1203
1265
  }
1204
1266
  isRtl() {
1205
1267
  return document.dir == 'rtl' || document.body.dir == 'rtl' || document.body.style.direction == 'rtl';
@@ -1221,6 +1283,9 @@ class AXPlatform {
1221
1283
  const _html = document.getElementsByTagName("html")[0];
1222
1284
  _html.classList.remove('ax-dark');
1223
1285
  }
1286
+ _setFullHeightRatio() {
1287
+ document.querySelector(':root').style.setProperty('--ax-vh', window.innerHeight / 100 + 'px');
1288
+ }
1224
1289
  }
1225
1290
  AXPlatform.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.1", ngImport: i0, type: AXPlatform, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1226
1291
  AXPlatform.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.1", ngImport: i0, type: AXPlatform, providedIn: 'platform' });