coject-hijri 1.0.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.
- package/LICENSE +21 -0
- package/coject-hijri.js +964 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Coject
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/coject-hijri.js
ADDED
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
// coject-hijri.js
|
|
2
|
+
// author: Akwad
|
|
3
|
+
// license: MIT
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
/************************************
|
|
8
|
+
Expose Coject Hijri
|
|
9
|
+
************************************/
|
|
10
|
+
(function (root, factory) {
|
|
11
|
+
/* global define */
|
|
12
|
+
if (typeof define === 'function' && define.amd) {
|
|
13
|
+
define(['moment/moment'], function (moment) {
|
|
14
|
+
root.moment = factory(moment)
|
|
15
|
+
return root.moment
|
|
16
|
+
})
|
|
17
|
+
} else if (typeof exports === 'object') {
|
|
18
|
+
module.exports = factory(require('moment/moment'))
|
|
19
|
+
} else {
|
|
20
|
+
root.moment = factory(root.moment)
|
|
21
|
+
}
|
|
22
|
+
})(this, function (moment) { // jshint ignore:line
|
|
23
|
+
|
|
24
|
+
if (moment == null) {
|
|
25
|
+
throw new Error('Cannot find moment')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/************************************
|
|
29
|
+
Constants
|
|
30
|
+
************************************/
|
|
31
|
+
|
|
32
|
+
var ummalqura = {
|
|
33
|
+
ummalquraData: [28607, 28636, 28665, 28695, 28724, 28754, 28783, 28813, 28843, 28872, 28901, 28931, 28960, 28990, 29019, 29049, 29078, 29108, 29137, 29167,
|
|
34
|
+
29196, 29226, 29255, 29285, 29315, 29345, 29375, 29404, 29434, 29463, 29492, 29522, 29551, 29580, 29610, 29640, 29669, 29699, 29729, 29759,
|
|
35
|
+
29788, 29818, 29847, 29876, 29906, 29935, 29964, 29994, 30023, 30053, 30082, 30112, 30141, 30171, 30200, 30230, 30259, 30289, 30318, 30348,
|
|
36
|
+
30378, 30408, 30437, 30467, 30496, 30526, 30555, 30585, 30614, 30644, 30673, 30703, 30732, 30762, 30791, 30821, 30850, 30880, 30909, 30939,
|
|
37
|
+
30968, 30998, 31027, 31057, 31086, 31116, 31145, 31175, 31204, 31234, 31263, 31293, 31322, 31352, 31381, 31411, 31441, 31471, 31500, 31530,
|
|
38
|
+
31559, 31589, 31618, 31648, 31676, 31706, 31736, 31766, 31795, 31825, 31854, 31884, 31913, 31943, 31972, 32002, 32031, 32061, 32090, 32120,
|
|
39
|
+
32150, 32180, 32209, 32239, 32268, 32298, 32327, 32357, 32386, 32416, 32445, 32475, 32504, 32534, 32563, 32593, 32622, 32652, 32681, 32711,
|
|
40
|
+
32740, 32770, 32799, 32829, 32858, 32888, 32917, 32947, 32976, 33006, 33035, 33065, 33094, 33124, 33153, 33183, 33213, 33243, 33272, 33302,
|
|
41
|
+
33331, 33361, 33390, 33420, 33450, 33479, 33509, 33539, 33568, 33598, 33627, 33657, 33686, 33716, 33745, 33775, 33804, 33834, 33863, 33893,
|
|
42
|
+
33922, 33952, 33981, 34011, 34040, 34069, 34099, 34128, 34158, 34187, 34217, 34247, 34277, 34306, 34336, 34365, 34395, 34424, 34454, 34483,
|
|
43
|
+
34512, 34542, 34571, 34601, 34631, 34660, 34690, 34719, 34749, 34778, 34808, 34837, 34867, 34896, 34926, 34955, 34985, 35015, 35044, 35074,
|
|
44
|
+
35103, 35133, 35162, 35192, 35222, 35251, 35280, 35310, 35340, 35370, 35399, 35429, 35458, 35488, 35517, 35547, 35576, 35605, 35635, 35665,
|
|
45
|
+
35694, 35723, 35753, 35782, 35811, 35841, 35871, 35901, 35930, 35960, 35989, 36019, 36048, 36078, 36107, 36136, 36166, 36195, 36225, 36254,
|
|
46
|
+
36284, 36314, 36343, 36373, 36403, 36433, 36462, 36492, 36521, 36551, 36580, 36610, 36639, 36669, 36698, 36728, 36757, 36786, 36816, 36845,
|
|
47
|
+
36875, 36904, 36934, 36963, 36993, 37022, 37052, 37081, 37111, 37141, 37170, 37200, 37229, 37259, 37288, 37318, 37347, 37377, 37406, 37436,
|
|
48
|
+
37465, 37495, 37524, 37554, 37584, 37613, 37643, 37672, 37701, 37731, 37760, 37790, 37819, 37849, 37878, 37908, 37938, 37967, 37997, 38027,
|
|
49
|
+
38056, 38085, 38115, 38144, 38174, 38203, 38233, 38262, 38292, 38322, 38351, 38381, 38410, 38440, 38469, 38499, 38528, 38558, 38587, 38617,
|
|
50
|
+
38646, 38676, 38705, 38735, 38764, 38794, 38823, 38853, 38882, 38912, 38941, 38971, 39001, 39030, 39059, 39089, 39118, 39148, 39178, 39208,
|
|
51
|
+
39237, 39267, 39297, 39326, 39355, 39385, 39414, 39444, 39473, 39503, 39532, 39562, 39592, 39621, 39650, 39680, 39709, 39739, 39768, 39798,
|
|
52
|
+
39827, 39857, 39886, 39916, 39946, 39975, 40005, 40035, 40064, 40094, 40123, 40153, 40182, 40212, 40241, 40271, 40300, 40330, 40359, 40389,
|
|
53
|
+
40418, 40448, 40477, 40507, 40536, 40566, 40595, 40625, 40655, 40685, 40714, 40744, 40773, 40803, 40832, 40862, 40892, 40921, 40951, 40980,
|
|
54
|
+
41009, 41039, 41068, 41098, 41127, 41157, 41186, 41216, 41245, 41275, 41304, 41334, 41364, 41393, 41422, 41452, 41481, 41511, 41540, 41570,
|
|
55
|
+
41599, 41629, 41658, 41688, 41718, 41748, 41777, 41807, 41836, 41865, 41894, 41924, 41953, 41983, 42012, 42042, 42072, 42102, 42131, 42161,
|
|
56
|
+
42190, 42220, 42249, 42279, 42308, 42337, 42367, 42397, 42426, 42456, 42485, 42515, 42545, 42574, 42604, 42633, 42662, 42692, 42721, 42751,
|
|
57
|
+
42780, 42810, 42839, 42869, 42899, 42929, 42958, 42988, 43017, 43046, 43076, 43105, 43135, 43164, 43194, 43223, 43253, 43283, 43312, 43342,
|
|
58
|
+
43371, 43401, 43430, 43460, 43489, 43519, 43548, 43578, 43607, 43637, 43666, 43696, 43726, 43755, 43785, 43814, 43844, 43873, 43903, 43932,
|
|
59
|
+
43962, 43991, 44021, 44050, 44080, 44109, 44139, 44169, 44198, 44228, 44258, 44287, 44317, 44346, 44375, 44405, 44434, 44464, 44493, 44523,
|
|
60
|
+
44553, 44582, 44612, 44641, 44671, 44700, 44730, 44759, 44788, 44818, 44847, 44877, 44906, 44936, 44966, 44996, 45025, 45055, 45084, 45114,
|
|
61
|
+
45143, 45172, 45202, 45231, 45261, 45290, 45320, 45350, 45380, 45409, 45439, 45468, 45498, 45527, 45556, 45586, 45615, 45644, 45674, 45704,
|
|
62
|
+
45733, 45763, 45793, 45823, 45852, 45882, 45911, 45940, 45970, 45999, 46028, 46058, 46088, 46117, 46147, 46177, 46206, 46236, 46265, 46295,
|
|
63
|
+
46324, 46354, 46383, 46413, 46442, 46472, 46501, 46531, 46560, 46590, 46620, 46649, 46679, 46708, 46738, 46767, 46797, 46826, 46856, 46885,
|
|
64
|
+
46915, 46944, 46974, 47003, 47033, 47063, 47092, 47122, 47151, 47181, 47210, 47240, 47269, 47298, 47328, 47357, 47387, 47417, 47446, 47476,
|
|
65
|
+
47506, 47535, 47565, 47594, 47624, 47653, 47682, 47712, 47741, 47771, 47800, 47830, 47860, 47890, 47919, 47949, 47978, 48008, 48037, 48066,
|
|
66
|
+
48096, 48125, 48155, 48184, 48214, 48244, 48273, 48303, 48333, 48362, 48392, 48421, 48450, 48480, 48509, 48538, 48568, 48598, 48627, 48657,
|
|
67
|
+
48687, 48717, 48746, 48776, 48805, 48834, 48864, 48893, 48922, 48952, 48982, 49011, 49041, 49071, 49100, 49130, 49160, 49189, 49218, 49248,
|
|
68
|
+
49277, 49306, 49336, 49365, 49395, 49425, 49455, 49484, 49514, 49543, 49573, 49602, 49632, 49661, 49690, 49720, 49749, 49779, 49809, 49838,
|
|
69
|
+
49868, 49898, 49927, 49957, 49986, 50016, 50045, 50075, 50104, 50133, 50163, 50192, 50222, 50252, 50281, 50311, 50340, 50370, 50400, 50429,
|
|
70
|
+
50459, 50488, 50518, 50547, 50576, 50606, 50635, 50665, 50694, 50724, 50754, 50784, 50813, 50843, 50872, 50902, 50931, 50960, 50990, 51019,
|
|
71
|
+
51049, 51078, 51108, 51138, 51167, 51197, 51227, 51256, 51286, 51315, 51345, 51374, 51403, 51433, 51462, 51492, 51522, 51552, 51582, 51611,
|
|
72
|
+
51641, 51670, 51699, 51729, 51758, 51787, 51816, 51846, 51876, 51906, 51936, 51965, 51995, 52025, 52054, 52083, 52113, 52142, 52171, 52200,
|
|
73
|
+
52230, 52260, 52290, 52319, 52349, 52379, 52408, 52438, 52467, 52497, 52526, 52555, 52585, 52614, 52644, 52673, 52703, 52733, 52762, 52792,
|
|
74
|
+
52822, 52851, 52881, 52910, 52939, 52969, 52998, 53028, 53057, 53087, 53116, 53146, 53176, 53205, 53235, 53264, 53294, 53324, 53353, 53383,
|
|
75
|
+
53412, 53441, 53471, 53500, 53530, 53559, 53589, 53619, 53648, 53678, 53708, 53737, 53767, 53796, 53825, 53855, 53884, 53913, 53943, 53973,
|
|
76
|
+
54003, 54032, 54062, 54092, 54121, 54151, 54180, 54209, 54239, 54268, 54297, 54327, 54357, 54387, 54416, 54446, 54476, 54505, 54535, 54564,
|
|
77
|
+
54593, 54623, 54652, 54681, 54711, 54741, 54770, 54800, 54830, 54859, 54889, 54919, 54948, 54977, 55007, 55036, 55066, 55095, 55125, 55154,
|
|
78
|
+
55184, 55213, 55243, 55273, 55302, 55332, 55361, 55391, 55420, 55450, 55479, 55508, 55538, 55567, 55597, 55627, 55657, 55686, 55716, 55745,
|
|
79
|
+
55775, 55804, 55834, 55863, 55892, 55922, 55951, 55981, 56011, 56040, 56070, 56100, 56129, 56159, 56188, 56218, 56247, 56276, 56306, 56335,
|
|
80
|
+
56365, 56394, 56424, 56454, 56483, 56513, 56543, 56572, 56601, 56631, 56660, 56690, 56719, 56749, 56778, 56808, 56837, 56867, 56897, 56926,
|
|
81
|
+
56956, 56985, 57015, 57044, 57074, 57103, 57133, 57162, 57192, 57221, 57251, 57280, 57310, 57340, 57369, 57399, 57429, 57458, 57487, 57517,
|
|
82
|
+
57546, 57576, 57605, 57634, 57664, 57694, 57723, 57753, 57783, 57813, 57842, 57871, 57901, 57930, 57959, 57989, 58018, 58048, 58077, 58107,
|
|
83
|
+
58137, 58167, 58196, 58226, 58255, 58285, 58314, 58343, 58373, 58402, 58432, 58461, 58491, 58521, 58551, 58580, 58610, 58639, 58669, 58698,
|
|
84
|
+
58727, 58757, 58786, 58816, 58845, 58875, 58905, 58934, 58964, 58994, 59023, 59053, 59082, 59111, 59141, 59170, 59200, 59229, 59259, 59288,
|
|
85
|
+
59318, 59348, 59377, 59407, 59436, 59466, 59495, 59525, 59554, 59584, 59613, 59643, 59672, 59702, 59731, 59761, 59791, 59820, 59850, 59879,
|
|
86
|
+
59909, 59939, 59968, 59997, 60027, 60056, 60086, 60115, 60145, 60174, 60204, 60234, 60264, 60293, 60323, 60352, 60381, 60411, 60440, 60469,
|
|
87
|
+
60499, 60528, 60558, 60588, 60618, 60648, 60677, 60707, 60736, 60765, 60795, 60824, 60853, 60883, 60912, 60942, 60972, 61002, 61031, 61061,
|
|
88
|
+
61090, 61120, 61149, 61179, 61208, 61237, 61267, 61296, 61326, 61356, 61385, 61415, 61445, 61474, 61504, 61533, 61563, 61592, 61621, 61651,
|
|
89
|
+
61680, 61710, 61739, 61769, 61799, 61828, 61858, 61888, 61917, 61947, 61976, 62006, 62035, 62064, 62094, 62123, 62153, 62182, 62212, 62242,
|
|
90
|
+
62271, 62301, 62331, 62360, 62390, 62419, 62448, 62478, 62507, 62537, 62566, 62596, 62625, 62655, 62685, 62715, 62744, 62774, 62803, 62832,
|
|
91
|
+
62862, 62891, 62921, 62950, 62980, 63009, 63039, 63069, 63099, 63128, 63157, 63187, 63216, 63246, 63275, 63305, 63334, 63363, 63393, 63423,
|
|
92
|
+
63453, 63482, 63512, 63541, 63571, 63600, 63630, 63659, 63689, 63718, 63747, 63777, 63807, 63836, 63866, 63895, 63925, 63955, 63984, 64014,
|
|
93
|
+
64043, 64073, 64102, 64131, 64161, 64190, 64220, 64249, 64279, 64309, 64339, 64368, 64398, 64427, 64457, 64486, 64515, 64545, 64574, 64603,
|
|
94
|
+
64633, 64663, 64692, 64722, 64752, 64782, 64811, 64841, 64870, 64899, 64929, 64958, 64987, 65017, 65047, 65076, 65106, 65136, 65166, 65195,
|
|
95
|
+
65225, 65254, 65283, 65313, 65342, 65371, 65401, 65431, 65460, 65490, 65520, 65549, 65579, 65608, 65638, 65667, 65697, 65726, 65755, 65785,
|
|
96
|
+
65815, 65844, 65874, 65903, 65933, 65963, 65992, 66022, 66051, 66081, 66110, 66140, 66169, 66199, 66228, 66258, 66287, 66317, 66346, 66376,
|
|
97
|
+
66405, 66435, 66465, 66494, 66524, 66553, 66583, 66612, 66641, 66671, 66700, 66730, 66760, 66789, 66819, 66849, 66878, 66908, 66937, 66967,
|
|
98
|
+
66996, 67025, 67055, 67084, 67114, 67143, 67173, 67203, 67233, 67262, 67292, 67321, 67351, 67380, 67409, 67439, 67468, 67497, 67527, 67557,
|
|
99
|
+
67587, 67617, 67646, 67676, 67705, 67735, 67764, 67793, 67823, 67852, 67882, 67911, 67941, 67971, 68000, 68030, 68060, 68089, 68119, 68148,
|
|
100
|
+
68177, 68207, 68236, 68266, 68295, 68325, 68354, 68384, 68414, 68443, 68473, 68502, 68532, 68561, 68591, 68620, 68650, 68679, 68708, 68738,
|
|
101
|
+
68768, 68797, 68827, 68857, 68886, 68916, 68946, 68975, 69004, 69034, 69063, 69092, 69122, 69152, 69181, 69211, 69240, 69270, 69300, 69330,
|
|
102
|
+
69359, 69388, 69418, 69447, 69476, 69506, 69535, 69565, 69595, 69624, 69654, 69684, 69713, 69743, 69772, 69802, 69831, 69861, 69890, 69919,
|
|
103
|
+
69949, 69978, 70008, 70038, 70067, 70097, 70126, 70156, 70186, 70215, 70245, 70274, 70303, 70333, 70362, 70392, 70421, 70451, 70481, 70510,
|
|
104
|
+
70540, 70570, 70599, 70629, 70658, 70687, 70717, 70746, 70776, 70805, 70835, 70864, 70894, 70924, 70954, 70983, 71013, 71042, 71071, 71101,
|
|
105
|
+
71130, 71159, 71189, 71218, 71248, 71278, 71308, 71337, 71367, 71397, 71426, 71455, 71485, 71514, 71543, 71573, 71602, 71632, 71662, 71691,
|
|
106
|
+
71721, 71751, 71781, 71810, 71839, 71869, 71898, 71927, 71957, 71986, 72016, 72046, 72075, 72105, 72135, 72164, 72194, 72223, 72253, 72282,
|
|
107
|
+
72311, 72341, 72370, 72400, 72429, 72459, 72489, 72518, 72548, 72577, 72607, 72637, 72666, 72695, 72725, 72754, 72784, 72813, 72843, 72872,
|
|
108
|
+
72902, 72931, 72961, 72991, 73020, 73050, 73080, 73109, 73139, 73168, 73197, 73227, 73256, 73286, 73315, 73345, 73375, 73404, 73434, 73464,
|
|
109
|
+
73493, 73523, 73552, 73581, 73611, 73640, 73669, 73699, 73729, 73758, 73788, 73818, 73848, 73877, 73907, 73936, 73965, 73995, 74024, 74053,
|
|
110
|
+
74083, 74113, 74142, 74172, 74202, 74231, 74261, 74291, 74320, 74349, 74379, 74408, 74437, 74467, 74497, 74526, 74556, 74586, 74615, 74645,
|
|
111
|
+
74675, 74704, 74733, 74763, 74792, 74822, 74851, 74881, 74910, 74940, 74969, 74999, 75029, 75058, 75088, 75117, 75147, 75176, 75206, 75235,
|
|
112
|
+
75264, 75294, 75323, 75353, 75383, 75412, 75442, 75472, 75501, 75531, 75560, 75590, 75619, 75648, 75678, 75707, 75737, 75766, 75796, 75826,
|
|
113
|
+
75856, 75885, 75915, 75944, 75974, 76003, 76032, 76062, 76091, 76121, 76150, 76180, 76210, 76239, 76269, 76299, 76328, 76358, 76387, 76416,
|
|
114
|
+
76446, 76475, 76505, 76534, 76564, 76593, 76623, 76653, 76682, 76712, 76741, 76771, 76801, 76830, 76859, 76889, 76918, 76948, 76977, 77007,
|
|
115
|
+
77036, 77066, 77096, 77125, 77155, 77185, 77214, 77243, 77273, 77302, 77332, 77361, 77390, 77420, 77450, 77479, 77509, 77539, 77569, 77598,
|
|
116
|
+
77627, 77657, 77686, 77715, 77745, 77774, 77804, 77833, 77863, 77893, 77923, 77952, 77982, 78011, 78041, 78070, 78099, 78129, 78158, 78188,
|
|
117
|
+
78217, 78247, 78277, 78307, 78336, 78366, 78395, 78425, 78454, 78483, 78513, 78542, 78572, 78601, 78631, 78661, 78690, 78720, 78750, 78779,
|
|
118
|
+
78808, 78838, 78867, 78897, 78926, 78956, 78985, 79015, 79044, 79074, 79104, 79133, 79163, 79192, 79222, 79251, 79281, 79310, 79340, 79369,
|
|
119
|
+
79399, 79428, 79458, 79487, 79517, 79546, 79576, 79606, 79635, 79665, 79695, 79724, 79753, 79783, 79812, 79841, 79871, 79900, 79930, 79960,
|
|
120
|
+
79990]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var formattingTokens = /(\[[^\[]*\])|(\\)?i(Mo|MM?M?M?|Do|DDDo|DD?D?D?|w[o|w]?|YYYYY|YYYY|YY|gg(ggg?)?)|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,
|
|
124
|
+
localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g
|
|
125
|
+
|
|
126
|
+
, parseTokenOneOrTwoDigits = /\d\d?/, parseTokenOneToThreeDigits = /\d{1,3}/, parseTokenThreeDigits = /\d{3}/, parseTokenFourDigits = /\d{1,4}/, parseTokenSixDigits = /[+\-]?\d{1,6}/, parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.?)|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, parseTokenT = /T/i, parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/
|
|
127
|
+
|
|
128
|
+
, unitAliases = {
|
|
129
|
+
hd: 'idate',
|
|
130
|
+
hm: 'imonth',
|
|
131
|
+
hy: 'iyear'
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
, formatFunctions = {}
|
|
135
|
+
|
|
136
|
+
, ordinalizeTokens = 'DDD w M D'.split(' '), paddedTokens = 'M D w'.split(' ')
|
|
137
|
+
|
|
138
|
+
, formatTokenFunctions = {
|
|
139
|
+
iM: function () {
|
|
140
|
+
return this.iMonth() + 1
|
|
141
|
+
},
|
|
142
|
+
iMMM: function (format) {
|
|
143
|
+
return this.localeData().iMonthsShort(this, format)
|
|
144
|
+
},
|
|
145
|
+
iMMMM: function (format) {
|
|
146
|
+
return this.localeData().iMonths(this, format)
|
|
147
|
+
},
|
|
148
|
+
iD: function () {
|
|
149
|
+
return this.iDate()
|
|
150
|
+
},
|
|
151
|
+
iDDD: function () {
|
|
152
|
+
return this.iDayOfYear()
|
|
153
|
+
},
|
|
154
|
+
iw: function () {
|
|
155
|
+
return this.iWeek()
|
|
156
|
+
},
|
|
157
|
+
iYY: function () {
|
|
158
|
+
return leftZeroFill(this.iYear() % 100, 2)
|
|
159
|
+
},
|
|
160
|
+
iYYYY: function () {
|
|
161
|
+
return leftZeroFill(this.iYear(), 4)
|
|
162
|
+
},
|
|
163
|
+
iYYYYY: function () {
|
|
164
|
+
return leftZeroFill(this.iYear(), 5)
|
|
165
|
+
},
|
|
166
|
+
igg: function () {
|
|
167
|
+
return leftZeroFill(this.iWeekYear() % 100, 2)
|
|
168
|
+
},
|
|
169
|
+
igggg: function () {
|
|
170
|
+
return this.iWeekYear()
|
|
171
|
+
},
|
|
172
|
+
iggggg: function () {
|
|
173
|
+
return leftZeroFill(this.iWeekYear(), 5)
|
|
174
|
+
}
|
|
175
|
+
}, i
|
|
176
|
+
|
|
177
|
+
function padToken(func, count) {
|
|
178
|
+
return function (a) {
|
|
179
|
+
return leftZeroFill(func.call(this, a), count)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function ordinalizeToken(func, period) {
|
|
184
|
+
return function (a) {
|
|
185
|
+
return this.localeData().ordinal(func.call(this, a), period)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
while (ordinalizeTokens.length) {
|
|
190
|
+
i = ordinalizeTokens.pop()
|
|
191
|
+
formatTokenFunctions['i' + i + 'o'] = ordinalizeToken(formatTokenFunctions['i' + i], i)
|
|
192
|
+
}
|
|
193
|
+
while (paddedTokens.length) {
|
|
194
|
+
i = paddedTokens.pop()
|
|
195
|
+
formatTokenFunctions['i' + i + i] = padToken(formatTokenFunctions['i' + i], 2)
|
|
196
|
+
}
|
|
197
|
+
formatTokenFunctions.iDDDD = padToken(formatTokenFunctions.iDDD, 3)
|
|
198
|
+
|
|
199
|
+
/************************************
|
|
200
|
+
Helpers
|
|
201
|
+
************************************/
|
|
202
|
+
|
|
203
|
+
function extend(a, b) {
|
|
204
|
+
var key
|
|
205
|
+
for (key in b)
|
|
206
|
+
if (b.hasOwnProperty(key))
|
|
207
|
+
a[key] = b[key]
|
|
208
|
+
return a
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function leftZeroFill(number, targetLength) {
|
|
212
|
+
var output = number + ''
|
|
213
|
+
while (output.length < targetLength)
|
|
214
|
+
output = '0' + output
|
|
215
|
+
return output
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function isArray(input) {
|
|
219
|
+
return Object.prototype.toString.call(input) === '[object Array]'
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function normalizeUnits(units) {
|
|
223
|
+
return units ? unitAliases[units] || units.toLowerCase().replace(/(.)s$/, '$1') : units
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function setDate(moment, year, month, date) {
|
|
227
|
+
var utc = moment._isUTC ? 'UTC' : ''
|
|
228
|
+
moment._d['set' + utc + 'FullYear'](year)
|
|
229
|
+
moment._d['set' + utc + 'Month'](month)
|
|
230
|
+
moment._d['set' + utc + 'Date'](date)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function objectCreate(parent) {
|
|
234
|
+
function F() {}
|
|
235
|
+
F.prototype = parent
|
|
236
|
+
return new F()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function getPrototypeOf(object) {
|
|
240
|
+
if (Object.getPrototypeOf)
|
|
241
|
+
return Object.getPrototypeOf(object)
|
|
242
|
+
else if (''.__proto__) // jshint ignore:line
|
|
243
|
+
return object.__proto__ // jshint ignore:line
|
|
244
|
+
else
|
|
245
|
+
return object.constructor.prototype
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/************************************
|
|
249
|
+
Languages
|
|
250
|
+
************************************/
|
|
251
|
+
extend(getPrototypeOf(moment.localeData()), {
|
|
252
|
+
_iMonths: ['Muharram'
|
|
253
|
+
, 'Safar'
|
|
254
|
+
, 'Rabi\' al-Awwal'
|
|
255
|
+
, 'Rabi\' al-Thani'
|
|
256
|
+
, 'Jumada al-Ula'
|
|
257
|
+
, 'Jumada al-Alkhirah'
|
|
258
|
+
, 'Rajab'
|
|
259
|
+
, 'Sha’ban'
|
|
260
|
+
, 'Ramadhan'
|
|
261
|
+
, 'Shawwal'
|
|
262
|
+
, 'Thul-Qi’dah'
|
|
263
|
+
, 'Thul-Hijjah'
|
|
264
|
+
],
|
|
265
|
+
iMonths: function (m) {
|
|
266
|
+
return this._iMonths[m.iMonth()]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
,
|
|
270
|
+
_iMonthsShort: ['Muh'
|
|
271
|
+
, 'Saf'
|
|
272
|
+
, 'Rab-I'
|
|
273
|
+
, 'Rab-II'
|
|
274
|
+
, 'Jum-I'
|
|
275
|
+
, 'Jum-II'
|
|
276
|
+
, 'Raj'
|
|
277
|
+
, 'Sha'
|
|
278
|
+
, 'Ram'
|
|
279
|
+
, 'Shw'
|
|
280
|
+
, 'Dhu-Q'
|
|
281
|
+
, 'Dhu-H'
|
|
282
|
+
],
|
|
283
|
+
iMonthsShort: function (m) {
|
|
284
|
+
return this._iMonthsShort[m.iMonth()]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
,
|
|
288
|
+
iMonthsParse: function (monthName) {
|
|
289
|
+
var i, mom, regex
|
|
290
|
+
if (!this._iMonthsParse)
|
|
291
|
+
this._iMonthsParse = []
|
|
292
|
+
for (i = 0; i < 12; i += 1) {
|
|
293
|
+
// Make the regex if we don't have it already.
|
|
294
|
+
if (!this._iMonthsParse[i]) {
|
|
295
|
+
mom = hMoment([2000, (2 + i) % 12, 25])
|
|
296
|
+
regex = '^' + this.iMonths(mom, '') + '$|^' + this.iMonthsShort(mom, '') + '$'
|
|
297
|
+
this._iMonthsParse[i] = new RegExp(regex.replace('.', ''), 'i')
|
|
298
|
+
}
|
|
299
|
+
// Test the regex.
|
|
300
|
+
if (this._iMonthsParse[i].test(monthName))
|
|
301
|
+
return i
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
var iMonthNames = {
|
|
306
|
+
iMonths: 'محرم_صفر_ربيع الأول_ربيع الثاني_جمادى الأولى_جمادى الآخرة_رجب_شعبان_رمضان_شوال_ذو القعدة_ذو الحجة'.split('_'),
|
|
307
|
+
iMonthsShort: 'محرم_صفر_ربيع ١_ربيع ٢_جمادى ١_جمادى ٢_رجب_شعبان_رمضان_شوال_ذو القعدة_ذو الحجة'.split('_')
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// Default to the momentjs 2.12+ API
|
|
311
|
+
if (typeof moment.updateLocale === 'function') {
|
|
312
|
+
moment.updateLocale('ar-sa', iMonthNames);
|
|
313
|
+
} else {
|
|
314
|
+
var oldLocale = moment.locale();
|
|
315
|
+
moment.defineLocale('ar-sa', iMonthNames);
|
|
316
|
+
moment.locale(oldLocale);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/************************************
|
|
320
|
+
Formatting
|
|
321
|
+
************************************/
|
|
322
|
+
|
|
323
|
+
function makeFormatFunction(format) {
|
|
324
|
+
var array = format.match(formattingTokens),
|
|
325
|
+
length = array.length,
|
|
326
|
+
i
|
|
327
|
+
|
|
328
|
+
for (i = 0; i < length; i += 1)
|
|
329
|
+
if (formatTokenFunctions[array[i]])
|
|
330
|
+
array[i] = formatTokenFunctions[array[i]]
|
|
331
|
+
|
|
332
|
+
return function (mom) {
|
|
333
|
+
var output = ''
|
|
334
|
+
for (i = 0; i < length; i += 1)
|
|
335
|
+
output += array[i] instanceof Function ? '[' + array[i].call(mom, format) + ']' : array[i]
|
|
336
|
+
return output
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/************************************
|
|
341
|
+
Parsing
|
|
342
|
+
************************************/
|
|
343
|
+
|
|
344
|
+
function getParseRegexForToken(token, config) {
|
|
345
|
+
switch (token) {
|
|
346
|
+
case 'iDDDD':
|
|
347
|
+
return parseTokenThreeDigits
|
|
348
|
+
case 'iYYYY':
|
|
349
|
+
return parseTokenFourDigits
|
|
350
|
+
case 'iYYYYY':
|
|
351
|
+
return parseTokenSixDigits
|
|
352
|
+
case 'iDDD':
|
|
353
|
+
return parseTokenOneToThreeDigits
|
|
354
|
+
case 'iMMM':
|
|
355
|
+
case 'iMMMM':
|
|
356
|
+
return parseTokenWord
|
|
357
|
+
case 'iMM':
|
|
358
|
+
case 'iDD':
|
|
359
|
+
case 'iYY':
|
|
360
|
+
case 'iM':
|
|
361
|
+
case 'iD':
|
|
362
|
+
return parseTokenOneOrTwoDigits
|
|
363
|
+
case 'DDDD':
|
|
364
|
+
return parseTokenThreeDigits
|
|
365
|
+
case 'YYYY':
|
|
366
|
+
return parseTokenFourDigits
|
|
367
|
+
case 'YYYYY':
|
|
368
|
+
return parseTokenSixDigits
|
|
369
|
+
case 'S':
|
|
370
|
+
case 'SS':
|
|
371
|
+
case 'SSS':
|
|
372
|
+
case 'DDD':
|
|
373
|
+
return parseTokenOneToThreeDigits
|
|
374
|
+
case 'MMM':
|
|
375
|
+
case 'MMMM':
|
|
376
|
+
case 'dd':
|
|
377
|
+
case 'ddd':
|
|
378
|
+
case 'dddd':
|
|
379
|
+
return parseTokenWord
|
|
380
|
+
case 'a':
|
|
381
|
+
case 'A':
|
|
382
|
+
return moment.localeData(config._l)._meridiemParse
|
|
383
|
+
case 'X':
|
|
384
|
+
return parseTokenTimestampMs
|
|
385
|
+
case 'Z':
|
|
386
|
+
case 'ZZ':
|
|
387
|
+
return parseTokenTimezone
|
|
388
|
+
case 'T':
|
|
389
|
+
return parseTokenT
|
|
390
|
+
case 'MM':
|
|
391
|
+
case 'DD':
|
|
392
|
+
case 'YY':
|
|
393
|
+
case 'HH':
|
|
394
|
+
case 'hh':
|
|
395
|
+
case 'mm':
|
|
396
|
+
case 'ss':
|
|
397
|
+
case 'M':
|
|
398
|
+
case 'D':
|
|
399
|
+
case 'd':
|
|
400
|
+
case 'H':
|
|
401
|
+
case 'h':
|
|
402
|
+
case 'm':
|
|
403
|
+
case 's':
|
|
404
|
+
return parseTokenOneOrTwoDigits
|
|
405
|
+
default:
|
|
406
|
+
return new RegExp(token.replace('\\', ''))
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function addTimeToArrayFromToken(token, input, config) {
|
|
411
|
+
var a, datePartArray = config._a
|
|
412
|
+
|
|
413
|
+
switch (token) {
|
|
414
|
+
case 'iM':
|
|
415
|
+
case 'iMM':
|
|
416
|
+
datePartArray[1] = input == null ? 0 : ~~input - 1
|
|
417
|
+
break
|
|
418
|
+
case 'iMMM':
|
|
419
|
+
case 'iMMMM':
|
|
420
|
+
a = moment.localeData(config._l).iMonthsParse(input)
|
|
421
|
+
if (a != null)
|
|
422
|
+
datePartArray[1] = a
|
|
423
|
+
else
|
|
424
|
+
config._isValid = false
|
|
425
|
+
break
|
|
426
|
+
case 'iD':
|
|
427
|
+
case 'iDD':
|
|
428
|
+
case 'iDDD':
|
|
429
|
+
case 'iDDDD':
|
|
430
|
+
if (input != null)
|
|
431
|
+
datePartArray[2] = ~~input
|
|
432
|
+
break
|
|
433
|
+
case 'iYY':
|
|
434
|
+
datePartArray[0] = ~~input + (~~input > 47 ? 1300 : 1400)
|
|
435
|
+
break
|
|
436
|
+
case 'iYYYY':
|
|
437
|
+
case 'iYYYYY':
|
|
438
|
+
datePartArray[0] = ~~input
|
|
439
|
+
}
|
|
440
|
+
if (input == null)
|
|
441
|
+
config._isValid = false
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function dateFromArray(config) {
|
|
445
|
+
var g, h, hy = config._a[0],
|
|
446
|
+
hm = config._a[1],
|
|
447
|
+
hd = config._a[2]
|
|
448
|
+
|
|
449
|
+
if ((hy == null) && (hm == null) && (hd == null))
|
|
450
|
+
return [0, 0, 1]
|
|
451
|
+
hy = hy || 0
|
|
452
|
+
hm = hm || 0
|
|
453
|
+
hd = hd || 1
|
|
454
|
+
if (hd < 1 || hd > hMoment.iDaysInMonth(hy, hm))
|
|
455
|
+
config._isValid = false
|
|
456
|
+
g = toGregorian(hy, hm, hd)
|
|
457
|
+
h = toHijri(g.gy, g.gm, g.gd)
|
|
458
|
+
config._hDiff = 0
|
|
459
|
+
if (~~h.hy !== hy)
|
|
460
|
+
config._hDiff += 1
|
|
461
|
+
if (~~h.hm !== hm)
|
|
462
|
+
config._hDiff += 1
|
|
463
|
+
if (~~h.hd !== hd)
|
|
464
|
+
config._hDiff += 1
|
|
465
|
+
return [g.gy, g.gm, g.gd]
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function makeDateFromStringAndFormat(config) {
|
|
469
|
+
var tokens = config._f.match(formattingTokens),
|
|
470
|
+
string = config._i,
|
|
471
|
+
len = tokens.length,
|
|
472
|
+
i, token, parsedInput
|
|
473
|
+
|
|
474
|
+
config._a = []
|
|
475
|
+
|
|
476
|
+
for (i = 0; i < len; i += 1) {
|
|
477
|
+
token = tokens[i]
|
|
478
|
+
parsedInput = (getParseRegexForToken(token, config).exec(string) || [])[0];
|
|
479
|
+
if (parsedInput)
|
|
480
|
+
string = string.slice(string.indexOf(parsedInput) + parsedInput.length)
|
|
481
|
+
if (formatTokenFunctions[token])
|
|
482
|
+
addTimeToArrayFromToken(token, parsedInput, config)
|
|
483
|
+
}
|
|
484
|
+
if (string)
|
|
485
|
+
config._il = string
|
|
486
|
+
|
|
487
|
+
return dateFromArray(config)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function makeDateFromStringAndArray(config, utc) {
|
|
491
|
+
var len = config._f.length
|
|
492
|
+
, i
|
|
493
|
+
, format
|
|
494
|
+
, tempMoment
|
|
495
|
+
, bestMoment
|
|
496
|
+
, currentScore
|
|
497
|
+
, scoreToBeat
|
|
498
|
+
|
|
499
|
+
if (len === 0) {
|
|
500
|
+
return makeMoment(new Date(NaN))
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
for (i = 0; i < len; i += 1) {
|
|
504
|
+
format = config._f[i]
|
|
505
|
+
currentScore = 0
|
|
506
|
+
tempMoment = makeMoment(config._i, format, config._l, utc)
|
|
507
|
+
|
|
508
|
+
if (!tempMoment.isValid()) continue
|
|
509
|
+
|
|
510
|
+
currentScore += tempMoment._hDiff
|
|
511
|
+
if (tempMoment._il)
|
|
512
|
+
currentScore += tempMoment._il.length
|
|
513
|
+
if (scoreToBeat == null || currentScore < scoreToBeat) {
|
|
514
|
+
scoreToBeat = currentScore
|
|
515
|
+
bestMoment = tempMoment
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return bestMoment
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function removeParsedTokens(config) {
|
|
523
|
+
var string = config._i,
|
|
524
|
+
input = '',
|
|
525
|
+
format = '',
|
|
526
|
+
array = config._f.match(formattingTokens),
|
|
527
|
+
len = array.length,
|
|
528
|
+
i, match, parsed
|
|
529
|
+
|
|
530
|
+
for (i = 0; i < len; i += 1) {
|
|
531
|
+
match = array[i]
|
|
532
|
+
parsed = (getParseRegexForToken(match, config).exec(string) || [])[0]
|
|
533
|
+
if (parsed)
|
|
534
|
+
string = string.slice(string.indexOf(parsed) + parsed.length)
|
|
535
|
+
if (!(formatTokenFunctions[match] instanceof Function)) {
|
|
536
|
+
format += match
|
|
537
|
+
if (parsed)
|
|
538
|
+
input += parsed
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
config._i = input
|
|
542
|
+
config._f = format
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/************************************
|
|
546
|
+
Week of Year
|
|
547
|
+
************************************/
|
|
548
|
+
|
|
549
|
+
function iWeekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
|
|
550
|
+
var end = firstDayOfWeekOfYear - firstDayOfWeek,
|
|
551
|
+
daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
|
|
552
|
+
adjustedMoment
|
|
553
|
+
|
|
554
|
+
if (daysToDayOfWeek > end) {
|
|
555
|
+
daysToDayOfWeek -= 7
|
|
556
|
+
}
|
|
557
|
+
if (daysToDayOfWeek < end - 7) {
|
|
558
|
+
daysToDayOfWeek += 7
|
|
559
|
+
}
|
|
560
|
+
adjustedMoment = hMoment(mom).add(daysToDayOfWeek, 'd')
|
|
561
|
+
return {
|
|
562
|
+
week: Math.ceil(adjustedMoment.iDayOfYear() / 7),
|
|
563
|
+
year: adjustedMoment.iYear()
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/************************************
|
|
568
|
+
Top Level Functions
|
|
569
|
+
************************************/
|
|
570
|
+
|
|
571
|
+
function makeMoment(input, format, lang, utc) {
|
|
572
|
+
var config =
|
|
573
|
+
{ _i: input
|
|
574
|
+
, _f: format
|
|
575
|
+
, _l: lang
|
|
576
|
+
}
|
|
577
|
+
, date
|
|
578
|
+
, m
|
|
579
|
+
, hm
|
|
580
|
+
if (format) {
|
|
581
|
+
if (isArray(format)) {
|
|
582
|
+
return makeDateFromStringAndArray(config, utc)
|
|
583
|
+
} else {
|
|
584
|
+
date = makeDateFromStringAndFormat(config)
|
|
585
|
+
removeParsedTokens(config)
|
|
586
|
+
format = 'YYYY-MM-DD-' + config._f
|
|
587
|
+
input = leftZeroFill(date[0], 4) + '-'
|
|
588
|
+
+ leftZeroFill(date[1] + 1, 2) + '-'
|
|
589
|
+
+ leftZeroFill(date[2], 2) + '-'
|
|
590
|
+
+ config._i
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (utc)
|
|
594
|
+
m = moment.utc(input, format, lang)
|
|
595
|
+
else
|
|
596
|
+
m = moment(input, format, lang)
|
|
597
|
+
if (config._isValid === false)
|
|
598
|
+
m._isValid = false
|
|
599
|
+
m._hDiff = config._hDiff || 0
|
|
600
|
+
hm = objectCreate(hMoment.fn)
|
|
601
|
+
extend(hm, m)
|
|
602
|
+
return hm
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function hMoment(input, format, lang) {
|
|
606
|
+
return makeMoment(input, format, lang, false)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
extend(hMoment, moment)
|
|
610
|
+
hMoment.fn = objectCreate(moment.fn)
|
|
611
|
+
|
|
612
|
+
hMoment.utc = function (input, format, lang) {
|
|
613
|
+
return makeMoment(input, format, lang, true)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/************************************
|
|
617
|
+
hMoment Prototype
|
|
618
|
+
************************************/
|
|
619
|
+
|
|
620
|
+
hMoment.fn.format = function (format) {
|
|
621
|
+
var i, replace, me = this
|
|
622
|
+
|
|
623
|
+
if (format) {
|
|
624
|
+
i = 5
|
|
625
|
+
replace = function (input) {
|
|
626
|
+
return me.localeData().longDateFormat(input) || input
|
|
627
|
+
}
|
|
628
|
+
while (i > 0 && localFormattingTokens.test(format)) {
|
|
629
|
+
i -= 1
|
|
630
|
+
format = format.replace(localFormattingTokens, replace)
|
|
631
|
+
}
|
|
632
|
+
if (!formatFunctions[format]) {
|
|
633
|
+
formatFunctions[format] = makeFormatFunction(format)
|
|
634
|
+
}
|
|
635
|
+
format = formatFunctions[format](this)
|
|
636
|
+
}
|
|
637
|
+
return moment.fn.format.call(this, format)
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
hMoment.fn.iYear = function (input) {
|
|
641
|
+
var lastDay, h, g
|
|
642
|
+
if (typeof input === 'number') {
|
|
643
|
+
h = toHijri(this.year(), this.month(), this.date())
|
|
644
|
+
lastDay = Math.min(h.hd, hMoment.iDaysInMonth(input, h.hm))
|
|
645
|
+
g = toGregorian(input, h.hm, lastDay)
|
|
646
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
647
|
+
//Workaround: sometimes moment wont set the date correctly if current day is the last in the month
|
|
648
|
+
if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) {
|
|
649
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
650
|
+
}
|
|
651
|
+
moment.updateOffset(this)
|
|
652
|
+
return this
|
|
653
|
+
} else {
|
|
654
|
+
return toHijri(this.year(), this.month(), this.date()).hy
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
hMoment.fn.iMonth = function (input) {
|
|
659
|
+
var lastDay, h, g
|
|
660
|
+
if (input != null) {
|
|
661
|
+
if (typeof input === 'string') {
|
|
662
|
+
input = this.localeData().iMonthsParse(input)
|
|
663
|
+
if(input >= 0) {
|
|
664
|
+
input -= 1
|
|
665
|
+
} else {
|
|
666
|
+
return this
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
h = toHijri(this.year(), this.month(), this.date())
|
|
670
|
+
lastDay = Math.min(h.hd, hMoment.iDaysInMonth(h.hy, input))
|
|
671
|
+
this.iYear(h.hy + div(input, 12))
|
|
672
|
+
input = mod(input, 12)
|
|
673
|
+
if (input < 0) {
|
|
674
|
+
input += 12
|
|
675
|
+
this.iYear(this.iYear() - 1)
|
|
676
|
+
}
|
|
677
|
+
g = toGregorian(this.iYear(), input, lastDay)
|
|
678
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
679
|
+
//Workaround: sometimes moment wont set the date correctly if current day is the last in the month
|
|
680
|
+
if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) {
|
|
681
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
682
|
+
}
|
|
683
|
+
moment.updateOffset(this)
|
|
684
|
+
return this
|
|
685
|
+
} else {
|
|
686
|
+
return toHijri(this.year(), this.month(), this.date()).hm
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
hMoment.fn.iDate = function (input) {
|
|
691
|
+
var h, g
|
|
692
|
+
if (typeof input === 'number') {
|
|
693
|
+
h = toHijri(this.year(), this.month(), this.date())
|
|
694
|
+
g = toGregorian(h.hy, h.hm, input)
|
|
695
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
696
|
+
//Workaround: sometimes moment wont set the date correctly if current day is the last in the month
|
|
697
|
+
if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) {
|
|
698
|
+
setDate(this, g.gy, g.gm, g.gd)
|
|
699
|
+
}
|
|
700
|
+
moment.updateOffset(this)
|
|
701
|
+
return this
|
|
702
|
+
} else {
|
|
703
|
+
return toHijri(this.year(), this.month(), this.date()).hd
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
hMoment.fn.iDayOfYear = function (input) {
|
|
708
|
+
var dayOfYear = Math.round((hMoment(this).startOf('day') - hMoment(this).startOf('iYear')) / 864e5) + 1
|
|
709
|
+
return input == null ? dayOfYear : this.add(input - dayOfYear, 'd')
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
hMoment.fn.iDaysInMonth = function () {
|
|
713
|
+
return parseInt(hMoment(this).endOf('iMonth').format('iDD'));
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
hMoment.fn.iWeek = function (input) {
|
|
717
|
+
var week = iWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).week
|
|
718
|
+
return input == null ? week : this.add( (input - week) * 7, 'd')
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
hMoment.fn.iWeekYear = function (input) {
|
|
722
|
+
var year = iWeekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year
|
|
723
|
+
return input == null ? year : this.add(input - year, 'y')
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
hMoment.fn.add = function (val, units) {
|
|
727
|
+
var temp
|
|
728
|
+
if (units !== null && !isNaN(+units)) {
|
|
729
|
+
temp = val
|
|
730
|
+
val = units
|
|
731
|
+
units = temp
|
|
732
|
+
}
|
|
733
|
+
units = normalizeUnits(units)
|
|
734
|
+
if (units === 'iyear') {
|
|
735
|
+
this.iYear(this.iYear() + val)
|
|
736
|
+
} else if (units === 'imonth') {
|
|
737
|
+
this.iMonth(this.iMonth() + val)
|
|
738
|
+
} else if (units === 'idate') {
|
|
739
|
+
this.iDate(this.iDate() + val)
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
moment.fn.add.call(this, val, units)
|
|
743
|
+
}
|
|
744
|
+
return this
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
hMoment.fn.subtract = function (val, units) {
|
|
748
|
+
var temp
|
|
749
|
+
if (units !== null && !isNaN(+units)) {
|
|
750
|
+
temp = val
|
|
751
|
+
val = units
|
|
752
|
+
units = temp
|
|
753
|
+
}
|
|
754
|
+
units = normalizeUnits(units)
|
|
755
|
+
if (units === 'iyear') {
|
|
756
|
+
this.iYear(this.iYear() - val)
|
|
757
|
+
} else if (units === 'imonth') {
|
|
758
|
+
this.iMonth(this.iMonth() - val)
|
|
759
|
+
} else if (units === 'idate') {
|
|
760
|
+
this.iDate(this.iDate() - val)
|
|
761
|
+
} else {
|
|
762
|
+
moment.fn.subtract.call(this, val, units)
|
|
763
|
+
}
|
|
764
|
+
return this
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
hMoment.fn.startOf = function (units) {
|
|
768
|
+
units = normalizeUnits(units)
|
|
769
|
+
if (units === 'iyear' || units === 'imonth') {
|
|
770
|
+
if (units === 'iyear') {
|
|
771
|
+
this.iMonth(0)
|
|
772
|
+
}
|
|
773
|
+
this.iDate(1)
|
|
774
|
+
this.hours(0)
|
|
775
|
+
this.minutes(0)
|
|
776
|
+
this.seconds(0)
|
|
777
|
+
this.milliseconds(0)
|
|
778
|
+
return this
|
|
779
|
+
} else {
|
|
780
|
+
return moment.fn.startOf.call(this, units)
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
hMoment.fn.endOf = function (units) {
|
|
785
|
+
units = normalizeUnits(units)
|
|
786
|
+
if (units === undefined || units === 'milisecond') {
|
|
787
|
+
return this
|
|
788
|
+
}
|
|
789
|
+
return this.startOf(units).add(1, (units === 'isoweek' ? 'week' : units)).subtract(1, 'milliseconds')
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
hMoment.fn.clone = function () {
|
|
793
|
+
return hMoment(this)
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
hMoment.fn.iYears = hMoment.fn.iYear
|
|
797
|
+
hMoment.fn.iMonths = hMoment.fn.iMonth
|
|
798
|
+
hMoment.fn.iDates = hMoment.fn.iDate
|
|
799
|
+
hMoment.fn.iWeeks = hMoment.fn.iWeek
|
|
800
|
+
|
|
801
|
+
/************************************
|
|
802
|
+
hMoment Statics
|
|
803
|
+
************************************/
|
|
804
|
+
|
|
805
|
+
hMoment.iDaysInMonth = function (year, month) {
|
|
806
|
+
var i = getNewMoonMJDNIndex(year, month + 1),
|
|
807
|
+
daysInMonth = ummalqura.ummalquraData[i] - ummalqura.ummalquraData[i - 1]
|
|
808
|
+
return daysInMonth
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function toHijri(gy, gm, gd) {
|
|
812
|
+
var h = d2h(g2d(gy, gm + 1, gd))
|
|
813
|
+
h.hm -= 1
|
|
814
|
+
return h
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function toGregorian(hy, hm, hd) {
|
|
818
|
+
var g = d2g(h2d(hy, hm + 1, hd))
|
|
819
|
+
g.gm -= 1
|
|
820
|
+
return g
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
hMoment.iConvert = {
|
|
824
|
+
toHijri: toHijri,
|
|
825
|
+
toGregorian: toGregorian
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return hMoment
|
|
829
|
+
|
|
830
|
+
/************************************
|
|
831
|
+
Hijri Conversion
|
|
832
|
+
************************************/
|
|
833
|
+
|
|
834
|
+
/*
|
|
835
|
+
Utility helper functions.
|
|
836
|
+
*/
|
|
837
|
+
|
|
838
|
+
function div(a, b) {
|
|
839
|
+
return~~ (a / b)
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function mod(a, b) {
|
|
843
|
+
return a - ~~(a / b) * b
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/*
|
|
847
|
+
Converts a date of the Hijri calendar to the Julian Day number.
|
|
848
|
+
|
|
849
|
+
@param hy Hijri year (1356 to 1500)
|
|
850
|
+
@param hm Hijri month (1 to 12)
|
|
851
|
+
@param hd Hijri day (1 to 29/30)
|
|
852
|
+
@return Julian Day number
|
|
853
|
+
*/
|
|
854
|
+
|
|
855
|
+
function h2d(hy, hm, hd) {
|
|
856
|
+
var i = getNewMoonMJDNIndex(hy, hm),
|
|
857
|
+
mjdn = hd + ummalqura.ummalquraData[i - 1] - 1,
|
|
858
|
+
jdn = mjdn + 2400000;
|
|
859
|
+
return jdn
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/*
|
|
863
|
+
Converts the Julian Day number to a date in the Hijri calendar.
|
|
864
|
+
|
|
865
|
+
@param jdn Julian Day number
|
|
866
|
+
@return
|
|
867
|
+
hy: Hijri year (1356 to 1500)
|
|
868
|
+
hm: Hijri month (1 to 12)
|
|
869
|
+
hd: Hijri day (1 to 29/30)
|
|
870
|
+
*/
|
|
871
|
+
|
|
872
|
+
function d2h(jdn) {
|
|
873
|
+
var mjdn = jdn - 2400000,
|
|
874
|
+
i = getNewMoonMJDNIndexByJDN(mjdn),
|
|
875
|
+
totalMonths = i + 16260,
|
|
876
|
+
cYears = Math.floor((totalMonths - 1) / 12),
|
|
877
|
+
hy = cYears + 1,
|
|
878
|
+
hm = totalMonths - 12 * cYears,
|
|
879
|
+
hd = mjdn - ummalqura.ummalquraData[i - 1] + 1
|
|
880
|
+
|
|
881
|
+
return {
|
|
882
|
+
hy: hy,
|
|
883
|
+
hm: hm,
|
|
884
|
+
hd: hd
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/*
|
|
889
|
+
Calculates the Julian Day number from Gregorian or Julian
|
|
890
|
+
calendar dates. This integer number corresponds to the noon of
|
|
891
|
+
the date (i.e. 12 hours of Universal Time).
|
|
892
|
+
The procedure was tested to be good since 1 March, -100100 (of both
|
|
893
|
+
calendars) up to a few million years into the future.
|
|
894
|
+
|
|
895
|
+
@param gy Calendar year (years BC numbered 0, -1, -2, ...)
|
|
896
|
+
@param gm Calendar month (1 to 12)
|
|
897
|
+
@param gd Calendar day of the month (1 to 28/29/30/31)
|
|
898
|
+
@return Julian Day number
|
|
899
|
+
*/
|
|
900
|
+
|
|
901
|
+
function g2d(gy, gm, gd) {
|
|
902
|
+
var d = div((gy + div(gm - 8, 6) + 100100) * 1461, 4) + div(153 * mod(gm + 9, 12) + 2, 5) + gd - 34840408
|
|
903
|
+
d = d - div(div(gy + 100100 + div(gm - 8, 6), 100) * 3, 4) + 752
|
|
904
|
+
return d
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/*
|
|
908
|
+
Calculates Gregorian and Julian calendar dates from the Julian Day number
|
|
909
|
+
(hdn) for the period since jdn=-34839655 (i.e. the year -100100 of both
|
|
910
|
+
calendars) to some millions years ahead of the present.
|
|
911
|
+
|
|
912
|
+
@param jdn Julian Day number
|
|
913
|
+
@return
|
|
914
|
+
gy: Calendar year (years BC numbered 0, -1, -2, ...)
|
|
915
|
+
gm: Calendar month (1 to 12)
|
|
916
|
+
gd: Calendar day of the month M (1 to 28/29/30/31)
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
function d2g(jdn) {
|
|
920
|
+
var j, i, gd, gm, gy
|
|
921
|
+
j = 4 * jdn + 139361631
|
|
922
|
+
j = j + div(div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908
|
|
923
|
+
i = div(mod(j, 1461), 4) * 5 + 308
|
|
924
|
+
gd = div(mod(i, 153), 5) + 1
|
|
925
|
+
gm = mod(div(i, 153), 12) + 1
|
|
926
|
+
gy = div(j, 1461) - 100100 + div(8 - gm, 6)
|
|
927
|
+
return {
|
|
928
|
+
gy: gy,
|
|
929
|
+
gm: gm,
|
|
930
|
+
gd: gd
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/*
|
|
935
|
+
Returns the index of the modified Julian day number of the new moon
|
|
936
|
+
by the given year and month
|
|
937
|
+
|
|
938
|
+
@param hy: Hijri year (1356 to 1500)
|
|
939
|
+
@param hm: Hijri month (1 to 12)
|
|
940
|
+
@return
|
|
941
|
+
i: the index of the new moon in modified Julian day number.
|
|
942
|
+
*/
|
|
943
|
+
function getNewMoonMJDNIndex(hy, hm) {
|
|
944
|
+
var cYears = hy - 1,
|
|
945
|
+
totalMonths = (cYears * 12) + 1 + (hm - 1),
|
|
946
|
+
i = totalMonths - 16260
|
|
947
|
+
return i
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/*
|
|
951
|
+
Returns the nearest new moon
|
|
952
|
+
|
|
953
|
+
@param jdn Julian Day number
|
|
954
|
+
@return
|
|
955
|
+
i: the index of a modified Julian day number.
|
|
956
|
+
*/
|
|
957
|
+
function getNewMoonMJDNIndexByJDN(mjdn) {
|
|
958
|
+
for (var i = 0; i < ummalqura.ummalquraData.length; i=i+1) {
|
|
959
|
+
if (ummalqura.ummalquraData[i] > mjdn)
|
|
960
|
+
return i
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "coject-hijri",
|
|
3
|
+
"description": "A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js.",
|
|
4
|
+
"author": "Akwad",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "coject-hijri.js",
|
|
7
|
+
"module": "coject-hijri.js",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/coject/coject-hijri.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"hijri",
|
|
14
|
+
"hijriah",
|
|
15
|
+
"arabic",
|
|
16
|
+
"lunar",
|
|
17
|
+
"Umm al-Qura",
|
|
18
|
+
"date",
|
|
19
|
+
"calendar",
|
|
20
|
+
"conversion",
|
|
21
|
+
"convert"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"moment": "^2.30.0"
|
|
25
|
+
},
|
|
26
|
+
"version": "1.0.0",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/coject/coject-hijri/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/coject/coject-hijri#readme"
|
|
34
|
+
}
|