| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979 |
1x
1x
1x
1x
1x
13x
7x
6x
6x
6x
6x
1x
1x
1x
1x
1x
1x
1x
1x
1x
9x
678x
1x
1x
678x
1x
292x
612x
230x
617x
672x
244x
244x
200x
244x
33x
33x
33x
21x
21x
12x
12x
33x
3x
30x
3x
27x
9x
18x
3x
15x
3x
12x
3x
33x
165x
1x
164x
5174x
1x
1x
44x
673x
1x
1x
1x
1x
1x
1x
1x
1x
1x
673x
672x
672x
672x
55x
617x
5x
612x
382x
382x
230x
228x
2x
1x
1x
1x
672x
672x
672x
672x
672x
1x
12x
1x
11x
11x
1x
1x
11x
1x
1x
11x
4x
4x
11x
1x
1x
11x
1x
1x
11x
3x
3x
11x
1x
1x
11x
10x
10x
1x
1x
10x
1x
1x
10x
3x
3x
10x
1x
1x
10x
1x
1x
10x
3x
3x
10x
1x
1x
10x
88x
88x
88x
82x
6x
1x
5x
4x
1x
88x
88x
88x
88x
88x
88x
311x
292x
19x
384x
51x
2x
45x
6x
1x
6x
45x
1x
45x
3x
50x
1x
1x
1x
1x
1x
2x
2x
1x
1x
1x
1x
1x
1x
1x
2x
46x
4x
4x
1x
1x
53x
1x
1x
1x
1x
1x
1x
1x
1x
1x
88x
44x
44x
44x
12x
12x
12x
12x
12x
12x
12x
12x
12x
1x
11x
1x
10x
12x
1x
12x
21x
6x
2x
3x
2x
2x
2x
3x
3x
1x
2x
1x
17x
2x
2x
2x
2x
3x
2x
2x
2x
3x
3x
1x
2x
3x
1x
1x
1x
89x
4x
4x
2x
2x
2x
2x
2x
2x
2x
2x
8x
8x
1x
7x
1x
6x
6x
6x
6x
6x
6x
6x
2x
2x
2x
2x
1x
1x
1x
34x
33x
33x
33x
32x
15x
4x
2x
1x
222x
234x
93x
93x
1x
92x
92x
92x
1x
225x
229x
3x
3x
3x
226x
237x
329x
6x
6x
6x
323x
229x
325x
3x
3x
3x
322x
229x
329x
3x
3x
3x
326x
1x
378x
8x
8x
8x
8x
8x
370x
1x
3x
374x
3x
3x
3x
3x
3x
371x
1x
415x
3x
3x
3x
3x
3x
412x
5x
5x
5x
1x
4x
1x
3x
1x
1x
37x
234x
2x
1x
1x
2x
1x
1x
1x
1x
12x
672x
1x
1x
1x
1x
1x
1x
672x
1x
714x
714x
714x
1905x
38x
1917x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
401x
2543x
2543x
2543x
2543x
2543x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
714x
1x
714x
714x
714x
714x
401x
401x
401x
714x
714x
714x
714x
709x
709x
709x
709x
410x
299x
82x
217x
25x
192x
13x
179x
161x
18x
12x
6x
6x
709x
709x
709x
709x
709x
709x
709x
709x
709x
709x
396x
396x
396x
396x
396x
396x
396x
396x
396x
396x
14x
1x
1x
33x
1x
1x
1x
1x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
33x
1x
2x
1x
1x
1x
292x
292x
292x
292x
292x
292x
668x
292x
668x
292x
1x
1x
1x
| /*!
*
* persian-date - 0.2.0
* Reza Babakhani <babakhani.reza@gmail.com>
* http://babakhani.github.io/PersianWebToolkit/docs/persian-date/
* Under WTFPL license
*
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
Eif(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["persianDate"] = factory();
else
root["persianDate"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Constants
* @module constants
*/
module.exports = {
durationUnit: {
year: ['y', 'years', 'year'],
month: ['M', 'months', 'month'],
day: ['d', 'days', 'day'],
hour: ['h', 'hours', 'hour'],
minute: ['m', 'minutes', 'minute'],
second: ['s', 'second', 'seconds'],
millisecond: ['ms', 'milliseconds', 'millisecond'],
week: ['w', '', 'weeks', 'week']
},
/**
*
* @type {number}
*/
GREGORIAN_EPOCH: 1721425.5,
/**
*
* @type {number}
*/
PERSIAN_EPOCH: 1948320.5,
/**
*
* @type {{}}
*/
monthRange: {
1: {
name: {
fa: "فروردین"
},
abbr: {
fa: "فرو"
}
},
2: {
name: {
fa: "اردیبهشت"
},
abbr: {
fa: "ارد"
}
},
3: {
name: {
fa: "خرداد"
},
abbr: {
fa: "خرد"
}
},
4: {
name: {
fa: "تیر"
},
abbr: {
fa: "تیر"
}
},
5: {
name: {
fa: "مرداد"
},
abbr: {
fa: "مرد"
}
},
6: {
name: {
fa: "شهریور"
},
abbr: {
fa: "شهر"
}
},
7: {
name: {
fa: "مهر"
},
abbr: {
fa: "مهر"
}
},
8: {
name: {
fa: "آبان"
},
abbr: {
fa: "آبا"
}
},
9: {
name: {
fa: "آذر"
},
abbr: {
fa: "آذر"
}
},
10: {
name: {
fa: "دی"
},
abbr: {
fa: "دی"
}
},
11: {
name: {
fa: "بهمن"
},
abbr: {
fa: "بهم"
}
},
12: {
name: {
fa: "اسفند"
},
abbr: {
fa: "اسف"
}
}
},
/**
*
* @type {{}}
*/
weekRange: {
1: {
name: {
fa: "شنبه"
},
abbr: {
fa: "ش"
}
},
2: {
name: {
fa: "یکشنبه"
},
abbr: {
fa: "ی"
}
},
3: {
name: {
fa: "دوشنبه"
},
abbr: {
fa: "د"
}
},
4: {
name: {
fa: "سه شنبه"
},
abbr: {
fa: "س"
}
},
5: {
name: {
fa: "چهار شنبه"
},
abbr: {
fa: "چ"
}
},
6: {
name: {
fa: "پنج شنبه"
},
abbr: {
fa: "پ"
}
},
0: {
name: {
fa: "جمعه"
},
abbr: {
fa: "ج"
}
}
},
/**
*
* @type {string[]}
*/
persianDaysName: ["اورمزد", "بهمن", "اوردیبهشت", "شهریور", "سپندارمذ", "خورداد", "امرداد", "دی به آذز", "آذز", "آبان", "خورشید", "ماه", "تیر", "گوش", "دی به مهر", "مهر", "سروش", "رشن", "فروردین", "بهرام", "رام", "باد", "دی به دین", "دین", "ارد", "اشتاد", "آسمان", "زامیاد", "مانتره سپند", "انارام", "زیادی"]
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var durationUnit = __webpack_require__(0).durationUnit;
var Helpers = function () {
function Helpers() {
_classCallCheck(this, Helpers);
}
_createClass(Helpers, [{
key: 'toPersianDigit',
/**
* @description return converted string to persian digit
* @param digit
* @returns {string|*}
*/
value: function toPersianDigit(digit) {
return digit.toString().toPersianDigit();
}
/**
* @param input
* @returns {boolean}
*/
}, {
key: 'isArray',
value: function isArray(input) {
return Object.prototype.toString.call(input) === '[object Array]';
}
/**
*
* @param input
* @returns {boolean}
*/
}, {
key: 'isNumber',
value: function isNumber(input) {
return typeof input === "number";
}
/**
*
* @param input
* @returns {boolean}
*/
}, {
key: 'isDate',
value: function isDate(input) {
return input instanceof Date;
}
/**
*
* @param input
* @returns {boolean}
*/
}, {
key: 'isUndefined',
value: function isUndefined(input) {
return typeof input === "undefined";
}
/**
* @param number
* @param targetLength
* @returns {string}
*/
}, {
key: 'leftZeroFill',
value: function leftZeroFill(number, targetLength) {
var output = number + '';
while (output.length < targetLength) {
output = '0' + output;
}
return output;
}
/**
* @description normalize duration params and return valid param
* @return {{unit: *, value: *}}
*/
}, {
key: 'normalizeDuration',
value: function normalizeDuration() {
var unit = void 0,
value = void 0;
if (typeof arguments[0] === "string") {
unit = arguments[0];
value = arguments[1];
} else {
value = arguments[0];
unit = arguments[1];
}
if (durationUnit.year.indexOf(unit) > -1) {
unit = 'year';
} else if (durationUnit.month.indexOf(unit) > -1) {
unit = 'month';
} else if (durationUnit.day.indexOf(unit) > -1) {
unit = 'day';
} else if (durationUnit.hour.indexOf(unit) > -1) {
unit = 'hour';
} else if (durationUnit.minute.indexOf(unit) > -1) {
unit = 'minute';
} else if (durationUnit.second.indexOf(unit) > -1) {
unit = 'second';
}
return {
unit: unit,
value: value
};
}
/**
*
* @param number
* @returns {number}
*/
}, {
key: 'absRound',
value: function absRound(number) {
if (number < 0) {
return Math.ceil(number);
} else {
return Math.floor(number);
}
}
/**
*
* @param a
* @param b
* @returns {number}
*/
}, {
key: 'mod',
value: function mod(a, b) {
return a - b * Math.floor(a / b);
}
}]);
return Helpers;
}();
module.exports = Helpers;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Eif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Algorithms = __webpack_require__(3);
var Helpers = __webpack_require__(1);
var Duration = __webpack_require__(4);
var toPersianDigit = new Helpers().toPersianDigit;
var leftZeroFill = new Helpers().leftZeroFill;
var weekRange = __webpack_require__(0).weekRange;
var persianDaysName = __webpack_require__(0).persianDaysName;
var monthRange = __webpack_require__(0).monthRange;
var PersianDateClass = function () {
function PersianDateClass(input) {
_classCallCheck(this, PersianDateClass);
this.algorithms = new Algorithms();
var helpers = new Helpers();
// Convert Any thing to Gregorian Date
if (helpers.isUndefined(input)) {
this.gDate = new Date();
} else if (helpers.isDate(input)) {
this.gDate = input;
} else if (helpers.isArray(input)) {
// Encapsulate Input Array
var arrayInput = input.slice();
this.gDate = this.algorithms.persianArrayToGregorianDate(arrayInput);
} else if (helpers.isNumber(input)) {
this.gDate = new Date(input);
}
// instance of pDate
else if (input instanceof PersianDateClass) {
this.gDate = input.gDate;
}
// ASP.NET JSON Date
else Eif (input.substring(0, 6) === "/Date(") {
this.gDate = new Date(parseInt(input.substr(6)));
} else {
this.gDate = new Date();
}
this.pDate = this.algorithms.toPersianDate(this.gDate);
this.version = "0.2.0";
this.formatPersian = "_default";
this._utcMode = false;
return this;
}
/**
* @description return Duration object
* @param input
* @param key
* @returns {Duration}
*/
_createClass(PersianDateClass, [{
key: 'duration',
value: function duration(input, key) {
return new Duration(input, key);
}
/**
* @description check if passed object is duration
* @param obj
* @returns {boolean}
*/
}, {
key: 'isDuration',
value: function isDuration(obj) {
return obj instanceof Duration;
}
/**
*
* @param key
* @param input
* @returns {PersianDate}
*/
}, {
key: 'add',
value: function add(key, value) {
var duration = new Duration(key, value)._data;
// log(duration)
if (duration.years > 0) {
var newYear = this.year() + duration.years;
this.year(newYear);
}
if (duration.months > 0) {
var newMonth = this.month() + duration.months;
this.month(newMonth);
}
if (duration.days > 0) {
var newDate = this.date() + duration.days;
this.date(newDate);
}
if (duration.hours > 0) {
var newHour = this.hour() + duration.hours;
this.hour(newHour);
}
if (duration.minutes > 0) {
var newMinute = this.minute() + duration.minutes;
this.minute(newMinute);
}
if (duration.seconds > 0) {
var newSecond = this.second() + duration.seconds;
this.second(newSecond);
}
if (duration.milliseconds > 0) {
// log('add millisecond')
var newMillisecond = this.milliseconds() + duration.milliseconds;
this.milliseconds(newMillisecond);
}
return new PersianDateClass(this.valueOf());
}
/**
*
* @param key
* @param input
* @returns {PersianDate}
*/
}, {
key: 'subtract',
value: function subtract(key, value) {
var duration = new Duration(key, value)._data;
// log(duration)
if (duration.years > 0) {
var newYear = this.year() - duration.years;
this.year(newYear);
}
if (duration.months > 0) {
var newMonth = this.month() - duration.months;
this.month(newMonth);
}
if (duration.days > 0) {
var newDate = this.date() - duration.days;
this.date(newDate);
}
if (duration.hours > 0) {
var newHour = this.hour() - duration.hours;
this.hour(newHour);
}
if (duration.minutes > 0) {
var newMinute = this.minute() - duration.minutes;
this.minute(newMinute);
}
if (duration.seconds > 0) {
var newSecond = this.second() - duration.seconds;
this.second(newSecond);
}
if (duration.milliseconds > 0) {
// log('add millisecond')
var newMillisecond = this.milliseconds() - duration.milliseconds;
this.milliseconds(newMillisecond);
}
return new PersianDateClass(this.valueOf());
}
/**
*
* @returns {*}
*/
}, {
key: 'formatNumber',
value: function formatNumber() {
var output = void 0,
self = this;
// if default conf dosent set follow golbal config
if (this.formatPersian === "_default") {
Eif (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
/* istanbul ignore next */
if (self.formatPersian === false) {
output = false;
} else {
// Default Conf
output = true;
}
}
/* istanbul ignore next */
else {
if (window.formatPersian === false) {
output = false;
} else {
// Default Conf
output = true;
}
}
} else {
if (this.formatPersian === true) {
output = true;
} else if (this.formatPersian === false) {
output = false;
} else {
Error("Invalid Config 'formatPersian' !!");
}
}
return output;
}
/**
*
* @param inputString
* @returns {*}
*/
}, {
key: 'format',
value: function format(inputString) {
var self = this,
formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DD?D?D?|ddddd|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|X|LT|ll?l?l?|LL?L?L?)/g,
info = {
year: self.year(),
month: self.month(),
hour: self.hours(),
minute: self.minutes(),
second: self.seconds(),
date: self.date(),
timezone: self.zone(),
unix: self.unix()
},
formatToPersian = self.formatNumber();
var checkPersian = function checkPersian(i) {
if (formatToPersian) {
return toPersianDigit(i);
} else {
return i;
}
};
/* jshint ignore:start */
function replaceFunction(input) {
switch (input) {
// AM/PM
case "a":
{
if (formatToPersian) return info.hour >= 12 ? 'ب ظ' : 'ق ظ';else return info.hour >= 12 ? 'PM' : 'AM';
}
// Hours (Int)
case "H":
{
return checkPersian(info.hour);
}
case "HH":
{
return checkPersian(leftZeroFill(info.hour, 2));
}
case "h":
{
return checkPersian(info.hour % 12);
}
case "hh":
{
return checkPersian(leftZeroFill(info.hour % 12, 2));
}
// Minutes
case "m":
{
return checkPersian(leftZeroFill(info.minute, 2));
}
// Two Digit Minutes
case "mm":
{
return checkPersian(leftZeroFill(info.minute, 2));
}
// Second
case "s":
{
return checkPersian(info.second);
}
case "ss":
{
return checkPersian(leftZeroFill(info.second, 2));
}
// Day (Int)
case "D":
{
return checkPersian(leftZeroFill(info.date));
}
// Return Two Digit
case "DD":
{
return checkPersian(leftZeroFill(info.date, 2));
}
// Return day Of Month
case "DDD":
{
var t = self.startOf("year");
return checkPersian(leftZeroFill(self.diff(t, "days"), 3));
}
// Return Day of Year
case "DDDD":
{
var _t = self.startOf("year");
return checkPersian(leftZeroFill(self.diff(_t, "days"), 3));
}
// Return day Of week
case "d":
{
return checkPersian(self.pDate.weekDayNumber);
}
// Return week day name abbr
case "ddd":
{
return weekRange[self.pDate.weekDayNumber].abbr.fa;
}
case "dddd":
{
return weekRange[self.pDate.weekDayNumber].name.fa;
}
// Return Persian Day Name
case "ddddd":
{
return persianDaysName[self.pDate.monthDayNumber];
}
// Return Persian Day Name
case "w":
{
var _t2 = self.startOf("year"),
day = parseInt(self.diff(_t2, "days") / 7) + 1;
return checkPersian(day);
}
// Return Persian Day Name
case "ww":
{
var _t3 = self.startOf("year"),
_day = leftZeroFill(parseInt(self.diff(_t3, "days") / 7) + 1, 2);
return checkPersian(_day);
}
// Month (Int)
case "M":
{
return checkPersian(info.month);
}
// Two Digit Month (Str)
case "MM":
{
return checkPersian(leftZeroFill(info.month, 2));
}
// Abbr String of Month (Str)
case "MMM":
{
return monthRange[info.month].abbr.fa;
}
// Full String name of Month (Str)
case "MMMM":
{
return monthRange[info.month].name.fa;
}
// Year
// Two Digit Year (Str)
case "YY":
{
var yearDigitArray = info.year.toString().split("");
return checkPersian(yearDigitArray[2] + yearDigitArray[3]);
}
// Full Year (Int)
case "YYYY":
{
return checkPersian(info.year);
}
/* istanbul ignore next */
case "Z":
{
var flag = "+",
hours = Math.round(info.timezone / 60),
minutes = info.timezone % 60;
if (minutes < 0) {
minutes *= -1;
}
if (hours < 0) {
flag = "-";
hours *= -1;
}
var z = flag + leftZeroFill(hours, 2) + ":" + leftZeroFill(minutes, 2);
return checkPersian(z);
}
/* istanbul ignore next */
case "ZZ":
{
var _flag = "+",
_hours = Math.round(info.timezone / 60),
_minutes = info.timezone % 60;
if (_minutes < 0) {
_minutes *= -1;
}
if (_hours < 0) {
_flag = "-";
_hours *= -1;
}
var _z = _flag + leftZeroFill(_hours, 2) + "" + leftZeroFill(_minutes, 2);
return checkPersian(_z);
}
/* istanbul ignore next */
case "X":
{
return self.unix();
}
// 8:30 PM
case "LT":
{
return self.format("h:m a");
}
// 09/04/1986
case "L":
{
return self.format("YYYY/MM/DD");
}
// 9/4/1986
case "l":
{
return self.format("YYYY/M/D");
}
// September 4th 1986
case "LL":
{
return self.format("MMMM DD YYYY");
}
// Sep 4 1986
case "ll":
{
return self.format("MMM DD YYYY");
}
//September 4th 1986 8:30 PM
case "LLL":
{
return self.format("MMMM YYYY DD h:m a");
}
// Sep 4 1986 8:30 PM
case "lll":
{
return self.format("MMM YYYY DD h:m a");
}
//Thursday, September 4th 1986 8:30 PM
case "LLLL":
{
return self.format("dddd D MMMM YYYY h:m a");
}
// Thu, Sep 4 1986 8:30 PM
case "llll":
{
return self.format("ddd D MMM YYYY h:m a");
}
}
}
/* jshint ignore:end */
if (inputString) {
return inputString.replace(formattingTokens, replaceFunction);
} else {
var _inputString = "YYYY-MM-DD HH:mm:ss a";
return _inputString.replace(formattingTokens, replaceFunction);
}
}
/**
*
* @param input
* @param val
* @param asFloat
* @returns {*}
*/
}, {
key: 'diff',
value: function diff(input, val, asFloat) {
var self = this,
inputMoment = input,
zoneDiff = 0,
diff = self.gDate - inputMoment.gDate - zoneDiff,
year = self.year() - inputMoment.year(),
month = self.month() - inputMoment.month(),
date = (self.date() - inputMoment.date()) * -1,
output = void 0;
if (val === 'months' || val === 'month') {
output = year * 12 + month + date / 30;
} else if (val === 'years' || val === 'year') {
output = year + (month + date / 30) / 12;
} else {
output = val === 'seconds' || val === 'second' ? diff / 1e3 : // 1000
val === 'minutes' || val === 'minute' ? diff / 6e4 : // 1000 * 60
val === 'hours' || val === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
val === 'days' || val === 'day' ? diff / 864e5 : // 1000 * 60 * 60 * 24
val === 'weeks' || val === 'week' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7
diff;
}
if (output < 0) {
output = output * -1;
}
return asFloat ? output : Math.round(output);
}
/**
*
* @param key
* @returns {*}
*/
}, {
key: 'startOf',
value: function startOf(key) {
// Simplify this\
/* jshint ignore:start */
switch (key) {
case "years":
case "year":
return new PersianDateClass([this.year(), 1, 1]);
case "months":
case "month":
return new PersianDateClass([this.year(), this.month(), 1]);
case "days":
case "day":
return new PersianDateClass([this.year(), this.month(), this.date(), 0, 0, 0]);
case "hours":
case "hour":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), 0, 0]);
case "minutes":
case "minute":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), this.minutes(), 0]);
case "seconds":
case "second":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), this.minutes(), this.seconds()]);
case "weeks":
case "week":
var weekDayNumber = this.pDate.weekDayNumber;
if (weekDayNumber === 0) {
return new PersianDateClass([this.year(), this.month(), this.date()]);
} else {
return new PersianDateClass([this.year(), this.month(), this.date()]).subtract("days", weekDayNumber);
}
default:
return this;
}
/* jshint ignore:end */
}
/**
*
* @param key
* @returns {*}
*/
}, {
key: 'endOf',
value: function endOf(key) {
// Simplify this
switch (key) {
case "years":
case "year":
var days = this.isLeapYear() ? 30 : 29;
return new PersianDateClass([this.year(), 12, days, 23, 59, 59]);
case "months":
case "month":
var monthDays = this.daysInMonth(this.year(), this.month());
return new PersianDateClass([this.year(), this.month(), monthDays, 23, 59, 59]);
case "days":
case "day":
return new PersianDateClass([this.year(), this.month(), this.date(), 23, 59, 59]);
case "hours":
case "hour":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), 59, 59]);
case "minutes":
case "minute":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), this.minutes(), 59]);
case "seconds":
case "second":
return new PersianDateClass([this.year(), this.month(), this.date(), this.hours(), this.minutes(), this.seconds()]);
case "weeks":
case "week":
var weekDayNumber = this.pDate.weekDayNumber;
if (weekDayNumber === 6) {
weekDayNumber = 7;
} else {
weekDayNumber = 6 - weekDayNumber;
}
return new PersianDateClass([this.year(), this.month(), this.date()]).add("days", weekDayNumber);
default:
return this;
}
}
/**
*
* @returns {*}
*/
}, {
key: 'sod',
value: function sod() {
return this.startOf("day");
}
/**
*
* @returns {*}
*/
}, {
key: 'eod',
value: function eod() {
return this.endOf("day");
}
/** Get the timezone offset in minutes.
* @return {*}
*/
}, {
key: 'zone',
value: function zone() {
return this.pDate.timeZoneOffset;
}
/**
*
* @returns {PersianDate}
*/
}, {
key: 'local',
value: function local() {
var utcStamp = void 0;
if (!this._utcMode) {
return this;
} else {
var offsetMils = this.pDate.timeZoneOffset * 60 * 1000;
Eif (this.pDate.timeZoneOffset < 0) {
utcStamp = this.valueOf() - offsetMils;
} else {
/* istanbul ignore next */
utcStamp = this.valueOf() + offsetMils;
}
this.gDate = new Date(utcStamp);
this._updatePDate();
this._utcMode = false;
return this;
}
}
}, {
key: 'utc',
/**
* Current date/time in UTC mode
* @param input
* @returns {*}
*/
value: function utc(input) {
var utcStamp = void 0;
if (input) {
return new PersianDateClass(input).utc();
}
if (this._utcMode) {
return this;
} else {
var offsetMils = this.pDate.timeZoneOffset * 60 * 1000;
Eif (this.pDate.timeZoneOffset < 0) {
utcStamp = this.valueOf() + offsetMils;
} else {
/* istanbul ignore next */
utcStamp = this.valueOf() - offsetMils;
}
this.gDate = new Date(utcStamp);
this._updatePDate();
this._utcMode = true;
return this;
}
}
/**
*
* @returns {boolean}
*/
}, {
key: 'isUtc',
value: function isUtc() {
return this._utcMode;
}
/**
*
* @returns {boolean}
* version 0.0.1
*/
}, {
key: 'isDST',
value: function isDST() {
var month = this.month(),
day = this.date();
if (month < 7) {
return false;
} else Eif (month == 7 && day >= 2 || month >= 7) {
return true;
}
}
/**
*
* @returns {boolean}
*/
}, {
key: 'isLeapYear',
value: function isLeapYear() {
return this.algorithms.isLeapPersian(this.year());
}
/**
*
* @param yearInput
* @param monthInput
* @returns {number}
*/
}, {
key: 'daysInMonth',
value: function daysInMonth(yearInput, monthInput) {
var year = yearInput ? yearInput : this.year(),
month = monthInput ? monthInput : this.month();
if (month < 1 || month > 12) return 0;
if (month < 7) return 31;
if (month < 12) return 30;
if (this.algorithms.isLeapPersian(year)) return 30;
return 29;
}
/**
* Return Native Javascript Date
* @returns {*|PersianDate.gDate}
*/
}, {
key: 'toDate',
value: function toDate() {
return this.gDate;
}
/**
* Returns Array Of Persian Date
* @returns {array}
*/
}, {
key: 'toArray',
value: function toArray() {
return [this.year(), this.month(), this.date(), this.hour(), this.minute(), this.second(), this.millisecond()];
}
/**
* Return Milliseconds since the Unix Epoch (1318874398806)
* @returns {*}
* @private
*/
}, {
key: '_valueOf',
value: function _valueOf() {
return this.gDate.valueOf();
}
// static unix(timestamp) {
// return this.unix(timestamp);
// }
}, {
key: 'unix',
/**
* Return Unix Timestamp (1318874398)
* @param timestamp
* @returns {*}
*/
value: function unix(timestamp) {
var output = void 0;
if (timestamp) {
return new PersianDateClass(timestamp * 1000);
} else {
var str = this.gDate.valueOf().toString();
output = str.substring(0, str.length - 3);
}
return parseInt(output);
}
/**
*
* @param obj
* @returns {boolean}
*/
}, {
key: 'isPersianDate',
value: function isPersianDate(obj) {
return obj instanceof PersianDateClass;
}
/**
*
* @param input
* @returns {*}
* Getter Setter
*/
}, {
key: 'millisecond',
value: function millisecond(input) {
return this.milliseconds(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'milliseconds',
value: function milliseconds(input) {
if (input) {
this.gDate.setMilliseconds(input);
this._updatePDate();
return this;
} else {
return this.pDate.milliseconds;
}
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'second',
value: function second(input) {
return this.seconds(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'seconds',
value: function seconds(input) {
if (input | input === 0) {
this.gDate.setSeconds(input);
this._updatePDate();
return this;
} else {
return this.pDate.seconds;
}
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'minute',
value: function minute(input) {
return this.minutes(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'minutes',
value: function minutes(input) {
if (input || input === 0) {
this.gDate.setMinutes(input);
this._updatePDate();
return this;
} else {
// TODO: remove this
return parseInt(this.pDate.minutes);
}
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'hour',
value: function hour(input) {
return this.hours(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'hours',
value: function hours(input) {
if (input | input === 0) {
this.gDate.setHours(input);
this._updatePDate();
return this;
} else {
return this.pDate.hours;
}
}
/**
* Day of Months
* @param input
* @returns {*}
*/
}, {
key: 'dates',
value: function dates(input) {
return this.date(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'date',
value: function date(input) {
if (input || input === 0) {
var pDateArray = this.algorithms.getPersianArrayFromPDate(this.pDate);
pDateArray[2] = input;
this.gDate = this.algorithms.persianArrayToGregorianDate(pDateArray);
this._updatePDate();
return this;
} else {
return this.pDate.date;
}
}
/**
* Day of week
* @returns {Function|Date.toJSON.day|date_json.day|PersianDate.day|day|output.day|*}
*/
}, {
key: 'days',
value: function days() {
return this.day();
}
/**
*
* @returns {Function|Date.toJSON.day|date_json.day|PersianDate.day|day|output.day|*}
*/
}, {
key: 'day',
value: function day() {
return this.pDate.day;
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'month',
value: function month(input) {
if (input | input === 0) {
var pDateArray = this.algorithms.getPersianArrayFromPDate(this.pDate);
pDateArray[1] = input;
this.gDate = this.algorithms.persianArrayToGregorianDate(pDateArray);
this._updatePDate();
return this;
} else {
return this.pDate.month;
}
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'years',
value: function years(input) {
return this.year(input);
}
/**
*
* @param input
* @returns {*}
*/
}, {
key: 'year',
value: function year(input) {
if (input | input === 0) {
var pDateArray = this.algorithms.getPersianArrayFromPDate(this.pDate);
pDateArray[0] = input;
this.gDate = this.algorithms.persianArrayToGregorianDate(pDateArray);
this._updatePDate();
return this;
} else {
return this.pDate.year;
}
}
/**
*
* @param year
* @param month
* @returns {*}
*/
}, {
key: 'getFirstWeekDayOfMonth',
value: function getFirstWeekDayOfMonth(year, month) {
var dateArray = this.algorithms.calcPersian(year, month, 1),
pdate = this.algorithms.calcGregorian(dateArray[0], dateArray[1], dateArray[2]);
if (pdate[3] + 2 === 8) {
return 1;
} else if (pdate[3] + 2 === 7) {
return 7;
} else {
return pdate[3] + 2;
}
}
/**
*
* @returns {PersianDate}
*/
}, {
key: 'clone',
value: function clone() {
var self = this;
return new PersianDateClass(self.gDate);
}
/**
*
* @private
*/
}, {
key: '_updatePDate',
value: function _updatePDate() {
this.pDate = this.algorithms.toPersianDate(this.gDate);
}
/**
*
* @returns {*}
*/
}, {
key: 'valueOf',
value: function valueOf() {
return this._valueOf();
}
}], [{
key: '_utc',
value: function _utc(input) {
if (input) {
return new PersianDateClass(input).utc();
} else {
return new PersianDateClass().utc();
}
}
}, {
key: '_unix',
value: function _unix(timestamp) {
if (timestamp) {
return new PersianDateClass(timestamp * 1000).unix();
} else {
return new PersianDateClass().unix();
}
}
}]);
return PersianDateClass;
}();
module.exports = PersianDateClass;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var GREGORIAN_EPOCH = __webpack_require__(0).GREGORIAN_EPOCH;
var PERSIAN_EPOCH = __webpack_require__(0).PERSIAN_EPOCH;
var Helpers = __webpack_require__(1);
var absRound = new Helpers().absRound;
var mod = new Helpers().mod;
/**
* @description Calendar algorithms implementations
* @author Reza Babakhani
*/
var Algorithms = function () {
function Algorithms() {
_classCallCheck(this, Algorithms);
}
_createClass(Algorithms, [{
key: 'jwday',
/**
* @param j
* @returns {*}
*/
value: function jwday(j) {
var mod = function mod(a, b) {
return a - b * Math.floor(a / b);
};
return mod(Math.floor(j + 1.5), 7);
}
/**
* @description Is a given year in the Gregorian calendar a leap year ?
* @param year
* @returns {boolean}
*/
}, {
key: 'isLeapGregorian',
value: function isLeapGregorian(year) {
return year % 4 === 0 && !(year % 100 === 0 && year % 400 !== 0);
}
/**
* @param year
* @returns {boolean}
*/
}, {
key: 'isLeapPersian',
value: function isLeapPersian(year) {
return ((year - (year > 0 ? 474 : 473)) % 2820 + 474 + 38) * 682 % 2816 < 682;
}
/**
* Determine Julian day number from Gregorian calendar date
* @param year
* @param month
* @param day
* @returns {number}
*/
}, {
key: 'gregorianToJd',
value: function gregorianToJd(year, month, day) {
return GREGORIAN_EPOCH - 1 + 365 * (year - 1) + Math.floor((year - 1) / 4) + -Math.floor((year - 1) / 100) + Math.floor((year - 1) / 400) + Math.floor((367 * month - 362) / 12 + (month <= 2 ? 0 : this.isLeapGregorian(year) ? -1 : -2) + day);
}
/**
* Calculate Gregorian calendar date from Julian day
* @param jd
* @returns {Array}
*/
}, {
key: 'jdToGregorian',
value: function jdToGregorian(jd) {
//let wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, dyindex, year, yearday, leapadj;
var wjd = Math.floor(jd - 0.5) + 0.5,
depoch = wjd - GREGORIAN_EPOCH,
quadricent = Math.floor(depoch / 146097),
dqc = mod(depoch, 146097),
cent = Math.floor(dqc / 36524),
dcent = mod(dqc, 36524),
quad = Math.floor(dcent / 1461),
dquad = mod(dcent, 1461),
yindex = Math.floor(dquad / 365),
year = quadricent * 400 + cent * 100 + quad * 4 + yindex;
Eif (!(cent == 4 || yindex == 4)) {
year++;
}
var yearday = wjd - this.gregorianToJd(year, 1, 1),
leapadj = wjd < this.gregorianToJd(year, 3, 1) ? 0 : this.isLeapGregorian(year) ? 1 : 2,
month = Math.floor(((yearday + leapadj) * 12 + 373) / 367),
day = wjd - this.gregorianToJd(year, month, 1) + 1;
return new Array(year, month, day);
}
/**
* Determine Julian day from Persian date
* @param year
* @param month
* @param day
* @returns {*}
*/
}, {
key: 'persianToJd',
value: function persianToJd(year, month, day) {
var epbase = void 0,
epyear = void 0;
epbase = year - (year >= 0 ? 474 : 473);
epyear = 474 + mod(epbase, 2820);
return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) + Math.floor((epyear * 682 - 110) / 2816) + (epyear - 1) * 365 + Math.floor(epbase / 2820) * 1029983 + (PERSIAN_EPOCH - 1);
}
/**
* Calculate Persian date from Julian day
* @param jd
* @returns {Array}
*/
}, {
key: 'jdToPersian',
value: function jdToPersian(jd) {
var year = void 0,
month = void 0,
day = void 0,
depoch = void 0,
cycle = void 0,
cyear = void 0,
ycycle = void 0,
aux1 = void 0,
aux2 = void 0,
yday = void 0;
jd = Math.floor(jd) + 0.5;
depoch = jd - this.persianToJd(475, 1, 1);
cycle = Math.floor(depoch / 1029983);
cyear = mod(depoch, 1029983);
Iif (cyear === 1029982) {
/* istanbul ignore next */
ycycle = 2820;
} else {
aux1 = Math.floor(cyear / 366);
aux2 = mod(cyear, 366);
ycycle = Math.floor((2134 * aux1 + 2816 * aux2 + 2815) / 1028522) + aux1 + 1;
}
year = ycycle + 2820 * cycle + 474;
if (year <= 0) {
year -= 1;
}
yday = jd - this.persianToJd(year, 1, 1) + 1;
month = yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30);
day = jd - this.persianToJd(year, month, 1) + 1;
return new Array(year, month, day);
}
/**
*
* @param year
* @param month
* @param day
* @returns {Array}
*/
}, {
key: 'calcPersian',
value: function calcPersian(year, month, day) {
var j = this.persianToJd(year, month, day),
date = this.jdToGregorian(j);
return new Array(date[0], date[1] - 1, date[2]);
}
/**
* Perform calculation starting with a Gregorian date
* @param year
* @param month
* @param day
* @returns {Array}
*/
}, {
key: 'calcGregorian',
value: function calcGregorian(year, month, day) {
// Update Julian day
var j = this.gregorianToJd(year, month + 1, day) + Math.floor(0 + 60 * (0 + 60 * 0) + 0.5) / 86400.0,
// Update Persian Calendar
perscal = this.jdToPersian(j),
weekday = this.jwday(j);
return new Array(perscal[0], perscal[1], perscal[2], weekday);
}
/**
* Converts a gregorian date to Jalali date for different formats
* @param gd
* @returns {{}}
*/
}, {
key: 'toPersianDate',
value: function toPersianDate(gd) {
var pa = this.calcGregorian(gd.getFullYear(), gd.getMonth(), gd.getDate()),
output = {};
output.monthDayNumber = pa[2] - 1;
if (pa[3] == 6) {
output.weekDayNumber = 1;
} else if (pa[3] === 5) {
output.weekDayNumber = 0;
} else if (pa[3] === 4) {
output.weekDayNumber = 6;
} else if (pa[3] === 3) {
output.weekDayNumber = 5;
} else if (pa[3] === 2) {
output.weekDayNumber = 4;
} else if (pa[3] === 1) {
output.weekDayNumber = 3;
} else Eif (pa[3] === 0) {
output.weekDayNumber = 2;
}
output.year = pa[0];
output.month = pa[1];
output.day = output.weekDayNumber;
output.date = pa[2];
output.hours = gd.getHours();
output.minutes = gd.getMinutes() < 10 ? '0' + gd.getMinutes() : gd.getMinutes();
output.seconds = gd.getSeconds();
output.milliseconds = gd.getMilliseconds();
output.timeZoneOffset = gd.getTimezoneOffset();
return output;
}
/**
*
* @param parray persian-date array
* @returns {Date}
*/
}, {
key: 'persianArrayToGregorianDate',
value: function persianArrayToGregorianDate(parray) {
// Howha : javascript Cant Parse this array truly 2011,2,20
var pd = this.calcPersian(parray[0] ? parray[0] : 0, parray[1] ? parray[1] : 1, parray[2] ? parray[2] : 1),
gDate = new Date(pd[0], pd[1], pd[2]);
gDate.setYear(pd[0]);
gDate.setMonth(pd[1]);
gDate.setDate(pd[2]);
gDate.setHours(parray[3] ? parray[3] : 0);
gDate.setMinutes(parray[4] ? parray[4] : 0);
gDate.setSeconds(parray[5] ? parray[5] : 0);
gDate.setMilliseconds(parray[6] ? parray[6] : 0);
return gDate;
}
/**
*
* @param pDate
* @returns {array}
*/
}, {
key: 'getPersianArrayFromPDate',
value: function getPersianArrayFromPDate(pDate) {
return [pDate.year, pDate.month, pDate.date, pDate.hours, pDate.minutes, pDate.seconds, pDate.milliseconds];
}
}]);
return Algorithms;
}();
module.exports = Algorithms;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Helpers = __webpack_require__(1);
var normalizeDuration = new Helpers().normalizeDuration;
var absRound = new Helpers().absRound;
/**
* Duration object constructor
* @param duration
* @class Duration
* @constructor
*/
var Duration = function Duration(key, value) {
_classCallCheck(this, Duration);
var duration = {},
data = this._data = {},
milliseconds = 0,
normalizedUnit = normalizeDuration(key, value),
unit = normalizedUnit.unit;
duration[unit] = normalizedUnit.value;
milliseconds = duration.milliseconds || duration.millisecond || duration.ms || 0;
var years = duration.years || duration.year || duration.y || 0,
months = duration.months || duration.month || duration.M || 0,
weeks = duration.weeks || duration.w || duration.week || 0,
days = duration.days || duration.d || duration.day || 0,
hours = duration.hours || duration.hour || duration.h || 0,
minutes = duration.minutes || duration.minute || duration.m || 0,
seconds = duration.seconds || duration.second || duration.s || 0;
// representation for dateAddRemove
this._milliseconds = milliseconds + seconds * 1e3 + minutes * 6e4 + hours * 36e5;
// Because of dateAddRemove treats 24 hours as different from a
// day when working around DST, we need to store them separately
this._days = days + weeks * 7;
// It is impossible translate months into days without knowing
// which months you are are talking about, so we have to store
// it separately.
this._months = months + years * 12;
// The following code bubbles up values, see the tests for
// examples of what that means.
data.milliseconds = milliseconds % 1000;
seconds += milliseconds / 1000;
data.seconds = seconds % 60;
minutes += absRound(seconds / 60);
data.minutes = minutes % 60;
hours += absRound(minutes / 60);
data.hours = hours % 24;
days += absRound(hours / 24);
days += weeks * 7;
data.days = days % 30;
months += absRound(days / 30);
data.months = months % 12;
years += absRound(months / 12);
data.years = years;
return this;
};
/**
*
* @type {{valueOf: Duration.valueOf}}
*/
Duration.prototype = {
valueOf: function valueOf() {
return this._milliseconds + this._days * 864e5 + this._months * 2592e6;
}
};
module.exports = Duration;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var PersianDateClass = __webpack_require__(2);
String.prototype.toPersianDigit = function (latinDigit) {
return this.replace(/\d+/g, function (digit) {
var enDigitArr = [],
peDigitArr = [],
i = void 0,
j = void 0;
for (i = 0; i < digit.length; i += 1) {
enDigitArr.push(digit.charCodeAt(i));
}
for (j = 0; j < enDigitArr.length; j += 1) {
peDigitArr.push(String.fromCharCode(enDigitArr[j] + (!!latinDigit && latinDigit === true ? 1584 : 1728)));
}
return peDigitArr.join('');
});
};
PersianDateClass.unix = PersianDateClass._unix;
PersianDateClass.utc = PersianDateClass._utc;
module.exports = PersianDateClass;
/***/ })
/******/ ]);
}); |