medivo 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/medivo/date.js +1078 -0
- data/app/assets/javascripts/medivo/helpers.coffee +31 -0
- data/app/assets/javascripts/medivo/lab_appointment/application.js +6 -0
- data/app/assets/javascripts/medivo/lab_appointment/handlers.coffee +31 -0
- data/app/assets/javascripts/medivo/lab_appointment/models.coffee +16 -0
- data/app/assets/javascripts/medivo/lab_appointment/sample/show_appointments.coffee +13 -0
- data/app/assets/javascripts/medivo/lab_appointment/views.coffee +9 -0
- data/app/assets/javascripts/medivo/lab_list/application.js +2 -1
- data/app/assets/javascripts/medivo/lab_list/{init.coffee → handlers.coffee} +7 -6
- data/app/assets/javascripts/medivo/lab_list/models.coffee +12 -54
- data/app/assets/javascripts/medivo/lab_list/sample/show_labs.coffee +8 -1
- data/app/assets/javascripts/medivo/lab_list/views.coffee +21 -30
- data/app/assets/javascripts/medivo/models.coffee +29 -0
- data/app/assets/javascripts/medivo/views.coffee +16 -0
- data/app/controllers/medivo/labs_controller.rb +10 -0
- data/app/models/medivo/appointment.rb +21 -0
- data/app/models/medivo/appointment_resource.rb +14 -0
- data/app/models/medivo/insurance_order.rb +1 -6
- data/app/models/medivo/lab.rb +11 -9
- data/app/models/medivo/lab_resource.rb +14 -0
- data/app/models/medivo/order.rb +2 -2
- data/app/models/medivo/primary_insurance.rb +6 -4
- data/app/models/medivo/resource_config.rb +16 -0
- data/config/routes.rb +1 -0
- data/lib/generators/medivo/appointments/appointments_generator.rb +15 -0
- data/lib/generators/medivo/labs/labs_generator.rb +33 -0
- data/lib/generators/medivo/templates/appointment_resource.yml +11 -0
- data/lib/generators/medivo/templates/lab_resource.yml +21 -0
- data/lib/generators/medivo/templates/labs_controller.rb +6 -0
- data/lib/generators/medivo/templates/search.html.haml +45 -0
- data/lib/medivo.rb +2 -1
- data/lib/medivo/fdf_generator.rb +36 -0
- data/lib/medivo/version.rb +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +2 -0
- data/spec/dummy/app/controllers/labs_controller.rb +3 -5
- data/spec/dummy/app/views/labs/search.html.haml +31 -1
- data/spec/dummy/config/medivo/appointment_resource.yml +12 -0
- data/spec/dummy/config/medivo/lab_resource.yml +21 -0
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/log/development.log +7782 -0
- data/spec/dummy/log/test.log +243 -0
- data/spec/dummy/tmp/cache/assets/C46/F00/sprockets%2F2281d588b540056c5a7306c32a3761b9 +0 -0
- data/spec/dummy/tmp/cache/assets/C69/500/sprockets%2F140b56780716711c2b6eb1028f042ca6 +0 -0
- data/spec/dummy/tmp/cache/assets/C6C/8D0/sprockets%2F2f423a28516973330a94ad121151f3bf +0 -0
- data/spec/dummy/tmp/cache/assets/C70/AC0/sprockets%2F25232afc7932c662d9d6f032030a2428 +0 -0
- data/spec/dummy/tmp/cache/assets/C81/D00/sprockets%2F64f056bd752d271308a86a6f865b1911 +0 -0
- data/spec/dummy/tmp/cache/assets/CB4/BD0/sprockets%2F3378f27c0d4f5e6d708665b22707a31f +0 -0
- data/spec/dummy/tmp/cache/assets/CC3/EF0/sprockets%2F453b504c1f8f374578636f699eaa455d +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/DA0/sprockets%2F622aa5281d15503829a5f7a0bf56fc29 +0 -0
- data/spec/dummy/tmp/cache/assets/CDD/820/sprockets%2Fb28231960c7ac62eff9048e702a29c70 +0 -0
- data/spec/dummy/tmp/cache/assets/CEC/EF0/sprockets%2F4b24a74018f693c06088bd52f8cc9f86 +0 -0
- data/spec/dummy/tmp/cache/assets/CEE/250/sprockets%2F96688f33f2f8aa261bf6701c1d6d7575 +0 -0
- data/spec/dummy/tmp/cache/assets/D07/6B0/sprockets%2F69a2df619ff14da071309dac4196400e +0 -0
- data/spec/dummy/tmp/cache/assets/D1B/820/sprockets%2F92a83e15913997b3d9ac7ed437b1e44c +0 -0
- data/spec/dummy/tmp/cache/assets/D20/F10/sprockets%2Fb2e907e4faa85fe755f4439e3b229088 +0 -0
- data/spec/dummy/tmp/cache/assets/D29/000/sprockets%2F61a10ddf57f1129c02a1049bfed6e007 +0 -0
- data/spec/dummy/tmp/cache/assets/D2C/F80/sprockets%2F399f6d5eb273936af7ff8f35a77c5037 +0 -0
- data/spec/dummy/tmp/cache/assets/D30/920/sprockets%2Fcc4603fc6441ca421a7d02886a81ab9d +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D36/870/sprockets%2Fce9e887568de873b133ae43d7c977f68 +0 -0
- data/spec/dummy/tmp/cache/assets/D3A/210/sprockets%2F4f9664dabb00038f85b417cc38bf83a1 +0 -0
- data/spec/dummy/tmp/cache/assets/D41/250/sprockets%2F7b3c4426715dcd1feedc4a95e5444256 +0 -0
- data/spec/dummy/tmp/cache/assets/D45/320/sprockets%2Fc50ff379a1bdf1dd4d22249058749cf6 +0 -0
- data/spec/dummy/tmp/cache/assets/D4C/7A0/sprockets%2Fbc635c7b186d1ef5178f4ed3722d868b +0 -0
- data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
- data/spec/dummy/tmp/cache/assets/D55/ED0/sprockets%2F0f673e42e816c6fe5b66a5c96f896f1a +0 -0
- data/spec/dummy/tmp/cache/assets/D5D/3E0/sprockets%2F63fea6cc142b5f02da93bf81e70b2116 +0 -0
- data/spec/dummy/tmp/cache/assets/D60/030/sprockets%2Ffc9485f617fc5e9b8918755d2e08ecc6 +0 -0
- data/spec/dummy/tmp/cache/assets/D64/C50/sprockets%2F22ee6fb2ab1ea9694ac7f0f41a406094 +0 -0
- data/spec/dummy/tmp/cache/assets/D65/6D0/sprockets%2F3ce07ca1958d7ab3e80c4b3e0d24088c +0 -0
- data/spec/dummy/tmp/cache/assets/D68/AD0/sprockets%2F19727663b4ec901b812dbdabee2526ec +0 -0
- data/spec/dummy/tmp/cache/assets/D69/130/sprockets%2Fbaa4ec50a34ce938c986612c2a47a64e +0 -0
- data/spec/dummy/tmp/cache/assets/D6E/700/sprockets%2Ff39fb8d8a25e4f3fd01a3e506ae31935 +0 -0
- data/spec/dummy/tmp/cache/assets/D74/9A0/sprockets%2F0ca4e6e833c72156fc7e7d5f007d9ce3 +0 -0
- data/spec/dummy/tmp/cache/assets/D76/720/sprockets%2F88d8aa1d2fb41ce79b8ec4150ea74748 +0 -0
- data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
- data/spec/dummy/tmp/cache/assets/D88/2C0/sprockets%2F452ab3ebb1912cf1c2ba617eec52a718 +0 -0
- data/spec/dummy/tmp/cache/assets/D9C/F50/sprockets%2F224e78bb9e1c414a2d518a3aaffd6f77 +0 -0
- data/spec/dummy/tmp/cache/assets/D9F/260/sprockets%2Fa3e040f83c30e4bbc1c79ffae57909e6 +0 -0
- data/spec/dummy/tmp/cache/assets/DA1/640/sprockets%2F91874cbba5e63cd19d6a7bd3c8362dc4 +0 -0
- data/spec/dummy/tmp/cache/assets/DC1/230/sprockets%2F3a36cd467bdce1914a2b7af4ed4114cf +0 -0
- data/spec/dummy/tmp/cache/assets/DCE/E80/sprockets%2Fc71ec62157b9cc7aabfc030955cef87b +0 -0
- data/spec/dummy/tmp/cache/assets/DD1/FD0/sprockets%2Fa531f33dc9c5852d39d64a9eda44dacf +0 -0
- data/spec/dummy/tmp/cache/assets/DD4/2B0/sprockets%2Fef214a63f29afe7f3cbffc65af943108 +0 -0
- data/spec/dummy/tmp/cache/assets/DFC/420/sprockets%2F502e2c683d1aaad6ac88966ffc4d2ade +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E32/FC0/sprockets%2Fe55fb2eef11567fe04fdaf7e73af5ba4 +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -1
- data/spec/models/orders_spec.rb +1 -23
- data/spec/models/primary_insurance_spec.rb +31 -0
- data/spec/requests/labs_spec.rb +0 -1
- data/spec/spec_helper.rb +7 -1
- data/spec/support/blueprints.rb +9 -1
- data/spec/support/helper.rb +9 -0
- metadata +94 -26
- data/app/assets/javascripts/medivo/lab_appointments/application.js +0 -0
- data/app/assets/javascripts/medivo/lab_appointments/models.coffee +0 -0
- data/app/assets/javascripts/medivo/lab_appointments/sample/show_appointments.coffee +0 -0
- data/app/assets/javascripts/medivo/lab_appointments/views.coffee +0 -0
- data/app/models/medivo/resource.rb +0 -24
- data/lib/generators/medivo/install/install_generator.rb +0 -41
- data/lib/generators/medivo/install/templates/medivo_resource.yml +0 -9
- data/spec/dummy/config/medivo_resource.yml +0 -12
@@ -0,0 +1,1078 @@
|
|
1
|
+
/**
|
2
|
+
* Version: 1.0 Alpha-1
|
3
|
+
* Build Date: 13-Nov-2007
|
4
|
+
* Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved.
|
5
|
+
* License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/.
|
6
|
+
* Website: http://www.datejs.com/ or http://www.coolite.com/datejs/
|
7
|
+
*/
|
8
|
+
Date.CultureInfo = {name:"en-US",englishName:"English (United States)",nativeName:"English (United States)",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbreviatedDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortestDayNames:["Su","Mo","Tu","We","Th","Fr","Sa"],firstLetterDayNames:["S","M","T","W","T","F","S"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbreviatedMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],amDesignator:"AM",pmDesignator:"PM",firstDayOfWeek:0,twoDigitYearMax:2029,dateElementOrder:"mdy",formatPatterns:{shortDate:"M/d/yyyy",longDate:"dddd, MMMM dd, yyyy",shortTime:"h:mm tt",longTime:"h:mm:ss tt",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",sortableDateTime:"yyyy-MM-ddTHH:mm:ss",universalSortableDateTime:"yyyy-MM-dd HH:mm:ssZ",rfc1123:"ddd, dd MMM yyyy HH:mm:ss GMT",monthDay:"MMMM dd",yearMonth:"MMMM, yyyy"},regexPatterns:{jan:/^jan(uary)?/i,feb:/^feb(ruary)?/i,mar:/^mar(ch)?/i,apr:/^apr(il)?/i,may:/^may/i,jun:/^jun(e)?/i,jul:/^jul(y)?/i,aug:/^aug(ust)?/i,sep:/^sep(t(ember)?)?/i,oct:/^oct(ober)?/i,nov:/^nov(ember)?/i,dec:/^dec(ember)?/i,sun:/^su(n(day)?)?/i,mon:/^mo(n(day)?)?/i,tue:/^tu(e(s(day)?)?)?/i,wed:/^we(d(nesday)?)?/i,thu:/^th(u(r(s(day)?)?)?)?/i,fri:/^fr(i(day)?)?/i,sat:/^sa(t(urday)?)?/i,future:/^next/i,past:/^last|past|prev(ious)?/i,add:/^(\+|after|from)/i,subtract:/^(\-|before|ago)/i,yesterday:/^yesterday/i,today:/^t(oday)?/i,tomorrow:/^tomorrow/i,now:/^n(ow)?/i,millisecond:/^ms|milli(second)?s?/i,second:/^sec(ond)?s?/i,minute:/^min(ute)?s?/i,hour:/^h(ou)?rs?/i,week:/^w(ee)?k/i,month:/^m(o(nth)?s?)?/i,day:/^d(ays?)?/i,year:/^y((ea)?rs?)?/i,shortMeridian:/^(a|p)/i,longMeridian:/^(a\.?m?\.?|p\.?m?\.?)/i,timezone:/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\s*(\+|\-)\s*\d\d\d\d?)|gmt)/i,ordinalSuffix:/^\s*(st|nd|rd|th)/i,timeContext:/^\s*(\:|a|p)/i},abbreviatedTimeZoneStandard:{GMT:"-000",EST:"-0400",CST:"-0500",MST:"-0600",PST:"-0700"},abbreviatedTimeZoneDST:{GMT:"-000",EDT:"-0500",CDT:"-0600",MDT:"-0700",PDT:"-0800"}};
|
9
|
+
Date.getMonthNumberFromName = function(name) {
|
10
|
+
var n = Date.CultureInfo.monthNames,m = Date.CultureInfo.abbreviatedMonthNames,s = name.toLowerCase();
|
11
|
+
for (var i = 0; i < n.length; i++) {
|
12
|
+
if (n[i].toLowerCase() == s || m[i].toLowerCase() == s) {
|
13
|
+
return i;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return-1;
|
17
|
+
};
|
18
|
+
Date.getDayNumberFromName = function(name) {
|
19
|
+
var n = Date.CultureInfo.dayNames,m = Date.CultureInfo.abbreviatedDayNames,o = Date.CultureInfo.shortestDayNames,s = name.toLowerCase();
|
20
|
+
for (var i = 0; i < n.length; i++) {
|
21
|
+
if (n[i].toLowerCase() == s || m[i].toLowerCase() == s) {
|
22
|
+
return i;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return-1;
|
26
|
+
};
|
27
|
+
Date.isLeapYear = function(year) {
|
28
|
+
return(((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
|
29
|
+
};
|
30
|
+
Date.getDaysInMonth = function(year, month) {
|
31
|
+
return[31,(Date.isLeapYear(year) ? 29 : 28),31,30,31,30,31,31,30,31,30,31][month];
|
32
|
+
};
|
33
|
+
Date.getTimezoneOffset = function(s, dst) {
|
34
|
+
return(dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST[s.toUpperCase()] : Date.CultureInfo.abbreviatedTimeZoneStandard[s.toUpperCase()];
|
35
|
+
};
|
36
|
+
Date.getTimezoneAbbreviation = function(offset, dst) {
|
37
|
+
var n = (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST : Date.CultureInfo.abbreviatedTimeZoneStandard,p;
|
38
|
+
for (p in n) {
|
39
|
+
if (n[p] === offset) {
|
40
|
+
return p;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return null;
|
44
|
+
};
|
45
|
+
Date.prototype.clone = function() {
|
46
|
+
return new Date(this.getTime());
|
47
|
+
};
|
48
|
+
Date.prototype.compareTo = function(date) {
|
49
|
+
if (isNaN(this)) {
|
50
|
+
throw new Error(this);
|
51
|
+
}
|
52
|
+
if (date instanceof Date && !isNaN(date)) {
|
53
|
+
return(this > date) ? 1 : (this < date) ? -1 : 0;
|
54
|
+
} else {
|
55
|
+
throw new TypeError(date);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
Date.prototype.equals = function(date) {
|
59
|
+
return(this.compareTo(date) === 0);
|
60
|
+
};
|
61
|
+
Date.prototype.between = function(start, end) {
|
62
|
+
var t = this.getTime();
|
63
|
+
return t >= start.getTime() && t <= end.getTime();
|
64
|
+
};
|
65
|
+
Date.prototype.addMilliseconds = function(value) {
|
66
|
+
this.setMilliseconds(this.getMilliseconds() + value);
|
67
|
+
return this;
|
68
|
+
};
|
69
|
+
Date.prototype.addSeconds = function(value) {
|
70
|
+
return this.addMilliseconds(value * 1000);
|
71
|
+
};
|
72
|
+
Date.prototype.addMinutes = function(value) {
|
73
|
+
return this.addMilliseconds(value * 60000);
|
74
|
+
};
|
75
|
+
Date.prototype.addHours = function(value) {
|
76
|
+
return this.addMilliseconds(value * 3600000);
|
77
|
+
};
|
78
|
+
Date.prototype.addDays = function(value) {
|
79
|
+
return this.addMilliseconds(value * 86400000);
|
80
|
+
};
|
81
|
+
Date.prototype.addWeeks = function(value) {
|
82
|
+
return this.addMilliseconds(value * 604800000);
|
83
|
+
};
|
84
|
+
Date.prototype.addMonths = function(value) {
|
85
|
+
var n = this.getDate();
|
86
|
+
this.setDate(1);
|
87
|
+
this.setMonth(this.getMonth() + value);
|
88
|
+
this.setDate(Math.min(n, this.getDaysInMonth()));
|
89
|
+
return this;
|
90
|
+
};
|
91
|
+
Date.prototype.addYears = function(value) {
|
92
|
+
return this.addMonths(value * 12);
|
93
|
+
};
|
94
|
+
Date.prototype.add = function(config) {
|
95
|
+
if (typeof config == "number") {
|
96
|
+
this._orient = config;
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
var x = config;
|
100
|
+
if (x.millisecond || x.milliseconds) {
|
101
|
+
this.addMilliseconds(x.millisecond || x.milliseconds);
|
102
|
+
}
|
103
|
+
if (x.second || x.seconds) {
|
104
|
+
this.addSeconds(x.second || x.seconds);
|
105
|
+
}
|
106
|
+
if (x.minute || x.minutes) {
|
107
|
+
this.addMinutes(x.minute || x.minutes);
|
108
|
+
}
|
109
|
+
if (x.hour || x.hours) {
|
110
|
+
this.addHours(x.hour || x.hours);
|
111
|
+
}
|
112
|
+
if (x.month || x.months) {
|
113
|
+
this.addMonths(x.month || x.months);
|
114
|
+
}
|
115
|
+
if (x.year || x.years) {
|
116
|
+
this.addYears(x.year || x.years);
|
117
|
+
}
|
118
|
+
if (x.day || x.days) {
|
119
|
+
this.addDays(x.day || x.days);
|
120
|
+
}
|
121
|
+
return this;
|
122
|
+
};
|
123
|
+
Date._validate = function(value, min, max, name) {
|
124
|
+
if (typeof value != "number") {
|
125
|
+
throw new TypeError(value + " is not a Number.");
|
126
|
+
} else if (value < min || value > max) {
|
127
|
+
throw new RangeError(value + " is not a valid value for " + name + ".");
|
128
|
+
}
|
129
|
+
return true;
|
130
|
+
};
|
131
|
+
Date.validateMillisecond = function(n) {
|
132
|
+
return Date._validate(n, 0, 999, "milliseconds");
|
133
|
+
};
|
134
|
+
Date.validateSecond = function(n) {
|
135
|
+
return Date._validate(n, 0, 59, "seconds");
|
136
|
+
};
|
137
|
+
Date.validateMinute = function(n) {
|
138
|
+
return Date._validate(n, 0, 59, "minutes");
|
139
|
+
};
|
140
|
+
Date.validateHour = function(n) {
|
141
|
+
return Date._validate(n, 0, 23, "hours");
|
142
|
+
};
|
143
|
+
Date.validateDay = function(n, year, month) {
|
144
|
+
return Date._validate(n, 1, Date.getDaysInMonth(year, month), "days");
|
145
|
+
};
|
146
|
+
Date.validateMonth = function(n) {
|
147
|
+
return Date._validate(n, 0, 11, "months");
|
148
|
+
};
|
149
|
+
Date.validateYear = function(n) {
|
150
|
+
return Date._validate(n, 1, 9999, "seconds");
|
151
|
+
};
|
152
|
+
Date.prototype.set = function(config) {
|
153
|
+
var x = config;
|
154
|
+
if (!x.millisecond && x.millisecond !== 0) {
|
155
|
+
x.millisecond = -1;
|
156
|
+
}
|
157
|
+
if (!x.second && x.second !== 0) {
|
158
|
+
x.second = -1;
|
159
|
+
}
|
160
|
+
if (!x.minute && x.minute !== 0) {
|
161
|
+
x.minute = -1;
|
162
|
+
}
|
163
|
+
if (!x.hour && x.hour !== 0) {
|
164
|
+
x.hour = -1;
|
165
|
+
}
|
166
|
+
if (!x.day && x.day !== 0) {
|
167
|
+
x.day = -1;
|
168
|
+
}
|
169
|
+
if (!x.month && x.month !== 0) {
|
170
|
+
x.month = -1;
|
171
|
+
}
|
172
|
+
if (!x.year && x.year !== 0) {
|
173
|
+
x.year = -1;
|
174
|
+
}
|
175
|
+
if (x.millisecond != -1 && Date.validateMillisecond(x.millisecond)) {
|
176
|
+
this.addMilliseconds(x.millisecond - this.getMilliseconds());
|
177
|
+
}
|
178
|
+
if (x.second != -1 && Date.validateSecond(x.second)) {
|
179
|
+
this.addSeconds(x.second - this.getSeconds());
|
180
|
+
}
|
181
|
+
if (x.minute != -1 && Date.validateMinute(x.minute)) {
|
182
|
+
this.addMinutes(x.minute - this.getMinutes());
|
183
|
+
}
|
184
|
+
if (x.hour != -1 && Date.validateHour(x.hour)) {
|
185
|
+
this.addHours(x.hour - this.getHours());
|
186
|
+
}
|
187
|
+
if (x.month !== -1 && Date.validateMonth(x.month)) {
|
188
|
+
this.addMonths(x.month - this.getMonth());
|
189
|
+
}
|
190
|
+
if (x.year != -1 && Date.validateYear(x.year)) {
|
191
|
+
this.addYears(x.year - this.getFullYear());
|
192
|
+
}
|
193
|
+
if (x.day != -1 && Date.validateDay(x.day, this.getFullYear(), this.getMonth())) {
|
194
|
+
this.addDays(x.day - this.getDate());
|
195
|
+
}
|
196
|
+
if (x.timezone) {
|
197
|
+
this.setTimezone(x.timezone);
|
198
|
+
}
|
199
|
+
if (x.timezoneOffset) {
|
200
|
+
this.setTimezoneOffset(x.timezoneOffset);
|
201
|
+
}
|
202
|
+
return this;
|
203
|
+
};
|
204
|
+
Date.prototype.clearTime = function() {
|
205
|
+
this.setHours(0);
|
206
|
+
this.setMinutes(0);
|
207
|
+
this.setSeconds(0);
|
208
|
+
this.setMilliseconds(0);
|
209
|
+
return this;
|
210
|
+
};
|
211
|
+
Date.prototype.isLeapYear = function() {
|
212
|
+
var y = this.getFullYear();
|
213
|
+
return(((y % 4 === 0) && (y % 100 !== 0)) || (y % 400 === 0));
|
214
|
+
};
|
215
|
+
Date.prototype.isWeekday = function() {
|
216
|
+
return!(this.is().sat() || this.is().sun());
|
217
|
+
};
|
218
|
+
Date.prototype.getDaysInMonth = function() {
|
219
|
+
return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
|
220
|
+
};
|
221
|
+
Date.prototype.moveToFirstDayOfMonth = function() {
|
222
|
+
return this.set({day:1});
|
223
|
+
};
|
224
|
+
Date.prototype.moveToLastDayOfMonth = function() {
|
225
|
+
return this.set({day:this.getDaysInMonth()});
|
226
|
+
};
|
227
|
+
Date.prototype.moveToDayOfWeek = function(day, orient) {
|
228
|
+
var diff = (day - this.getDay() + 7 * (orient || +1)) % 7;
|
229
|
+
return this.addDays((diff === 0) ? diff += 7 * (orient || +1) : diff);
|
230
|
+
};
|
231
|
+
Date.prototype.moveToMonth = function(month, orient) {
|
232
|
+
var diff = (month - this.getMonth() + 12 * (orient || +1)) % 12;
|
233
|
+
return this.addMonths((diff === 0) ? diff += 12 * (orient || +1) : diff);
|
234
|
+
};
|
235
|
+
Date.prototype.getDayOfYear = function() {
|
236
|
+
return Math.floor((this - new Date(this.getFullYear(), 0, 1)) / 86400000);
|
237
|
+
};
|
238
|
+
Date.prototype.getWeekOfYear = function(firstDayOfWeek) {
|
239
|
+
var y = this.getFullYear(),m = this.getMonth(),d = this.getDate();
|
240
|
+
var dow = firstDayOfWeek || Date.CultureInfo.firstDayOfWeek;
|
241
|
+
var offset = 7 + 1 - new Date(y, 0, 1).getDay();
|
242
|
+
if (offset == 8) {
|
243
|
+
offset = 1;
|
244
|
+
}
|
245
|
+
var daynum = ((Date.UTC(y, m, d, 0, 0, 0) - Date.UTC(y, 0, 1, 0, 0, 0)) / 86400000) + 1;
|
246
|
+
var w = Math.floor((daynum - offset + 7) / 7);
|
247
|
+
if (w === dow) {
|
248
|
+
y--;
|
249
|
+
var prevOffset = 7 + 1 - new Date(y, 0, 1).getDay();
|
250
|
+
if (prevOffset == 2 || prevOffset == 8) {
|
251
|
+
w = 53;
|
252
|
+
} else {
|
253
|
+
w = 52;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return w;
|
257
|
+
};
|
258
|
+
Date.prototype.isDST = function() {
|
259
|
+
console.log('isDST');
|
260
|
+
return this.toString().match(/(E|C|M|P)(S|D)T/)[2] == "D";
|
261
|
+
};
|
262
|
+
Date.prototype.getTimezone = function() {
|
263
|
+
return Date.getTimezoneAbbreviation(this.getUTCOffset, this.isDST());
|
264
|
+
};
|
265
|
+
Date.prototype.setTimezoneOffset = function(s) {
|
266
|
+
var here = this.getTimezoneOffset(),there = Number(s) * -6 / 10;
|
267
|
+
this.addMinutes(there - here);
|
268
|
+
return this;
|
269
|
+
};
|
270
|
+
Date.prototype.setTimezone = function(s) {
|
271
|
+
return this.setTimezoneOffset(Date.getTimezoneOffset(s));
|
272
|
+
};
|
273
|
+
Date.prototype.getUTCOffset = function() {
|
274
|
+
var n = this.getTimezoneOffset() * -10 / 6,r;
|
275
|
+
if (n < 0) {
|
276
|
+
r = (n - 10000).toString();
|
277
|
+
return r[0] + r.substr(2);
|
278
|
+
} else {
|
279
|
+
r = (n + 10000).toString();
|
280
|
+
return"+" + r.substr(1);
|
281
|
+
}
|
282
|
+
};
|
283
|
+
Date.prototype.getDayName = function(abbrev) {
|
284
|
+
return abbrev ? Date.CultureInfo.abbreviatedDayNames[this.getDay()] : Date.CultureInfo.dayNames[this.getDay()];
|
285
|
+
};
|
286
|
+
Date.prototype.getMonthName = function(abbrev) {
|
287
|
+
return abbrev ? Date.CultureInfo.abbreviatedMonthNames[this.getMonth()] : Date.CultureInfo.monthNames[this.getMonth()];
|
288
|
+
};
|
289
|
+
Date.prototype._toString = Date.prototype.toString;
|
290
|
+
Date.prototype.toString = function(format) {
|
291
|
+
var self = this;
|
292
|
+
var p = function p(s) {
|
293
|
+
return(s.toString().length == 1) ? "0" + s : s;
|
294
|
+
};
|
295
|
+
return format ? format.replace(/dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?/g, function(format) {
|
296
|
+
switch (format) {
|
297
|
+
case"hh":
|
298
|
+
return p(self.getHours() < 13 ? self.getHours() : (self.getHours() - 12));
|
299
|
+
case"h":
|
300
|
+
return self.getHours() < 13 ? self.getHours() : (self.getHours() - 12);
|
301
|
+
case"HH":
|
302
|
+
return p(self.getHours());
|
303
|
+
case"H":
|
304
|
+
return self.getHours();
|
305
|
+
case"mm":
|
306
|
+
return p(self.getMinutes());
|
307
|
+
case"m":
|
308
|
+
return self.getMinutes();
|
309
|
+
case"ss":
|
310
|
+
return p(self.getSeconds());
|
311
|
+
case"s":
|
312
|
+
return self.getSeconds();
|
313
|
+
case"yyyy":
|
314
|
+
return self.getFullYear();
|
315
|
+
case"yy":
|
316
|
+
return self.getFullYear().toString().substring(2, 4);
|
317
|
+
case"dddd":
|
318
|
+
return self.getDayName();
|
319
|
+
case"ddd":
|
320
|
+
return self.getDayName(true);
|
321
|
+
case"dd":
|
322
|
+
return p(self.getDate());
|
323
|
+
case"d":
|
324
|
+
return self.getDate().toString();
|
325
|
+
case"MMMM":
|
326
|
+
return self.getMonthName();
|
327
|
+
case"MMM":
|
328
|
+
return self.getMonthName(true);
|
329
|
+
case"MM":
|
330
|
+
return p((self.getMonth() + 1));
|
331
|
+
case"M":
|
332
|
+
return self.getMonth() + 1;
|
333
|
+
case"t":
|
334
|
+
return self.getHours() < 12 ? Date.CultureInfo.amDesignator.substring(0, 1) : Date.CultureInfo.pmDesignator.substring(0, 1);
|
335
|
+
case"tt":
|
336
|
+
return self.getHours() < 12 ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
|
337
|
+
case"zzz":
|
338
|
+
case"zz":
|
339
|
+
case"z":
|
340
|
+
return"";
|
341
|
+
}
|
342
|
+
}) : this._toString();
|
343
|
+
};
|
344
|
+
Date.now = function() {
|
345
|
+
return new Date();
|
346
|
+
};
|
347
|
+
Date.today = function() {
|
348
|
+
return Date.now().clearTime();
|
349
|
+
};
|
350
|
+
Date.prototype._orient = +1;
|
351
|
+
Date.prototype.next = function() {
|
352
|
+
this._orient = +1;
|
353
|
+
return this;
|
354
|
+
};
|
355
|
+
Date.prototype.last = Date.prototype.prev = Date.prototype.previous = function() {
|
356
|
+
this._orient = -1;
|
357
|
+
return this;
|
358
|
+
};
|
359
|
+
Date.prototype._is = false;
|
360
|
+
Date.prototype.is = function() {
|
361
|
+
this._is = true;
|
362
|
+
return this;
|
363
|
+
};
|
364
|
+
Number.prototype._dateElement = "day";
|
365
|
+
Number.prototype.fromNow = function() {
|
366
|
+
var c = {};
|
367
|
+
c[this._dateElement] = this;
|
368
|
+
return Date.now().add(c);
|
369
|
+
};
|
370
|
+
Number.prototype.ago = function() {
|
371
|
+
var c = {};
|
372
|
+
c[this._dateElement] = this * -1;
|
373
|
+
return Date.now().add(c);
|
374
|
+
};
|
375
|
+
(function() {
|
376
|
+
var $D = Date.prototype,$N = Number.prototype;
|
377
|
+
var dx = ("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),mx = ("january february march april may june july august september october november december").split(/\s/),px = ("Millisecond Second Minute Hour Day Week Month Year").split(/\s/),de;
|
378
|
+
var df = function(n) {
|
379
|
+
return function() {
|
380
|
+
if (this._is) {
|
381
|
+
this._is = false;
|
382
|
+
return this.getDay() == n;
|
383
|
+
}
|
384
|
+
return this.moveToDayOfWeek(n, this._orient);
|
385
|
+
};
|
386
|
+
};
|
387
|
+
for (var i = 0; i < dx.length; i++) {
|
388
|
+
$D[dx[i]] = $D[dx[i].substring(0, 3)] = df(i);
|
389
|
+
}
|
390
|
+
var mf = function(n) {
|
391
|
+
return function() {
|
392
|
+
if (this._is) {
|
393
|
+
this._is = false;
|
394
|
+
return this.getMonth() === n;
|
395
|
+
}
|
396
|
+
return this.moveToMonth(n, this._orient);
|
397
|
+
};
|
398
|
+
};
|
399
|
+
for (var j = 0; j < mx.length; j++) {
|
400
|
+
$D[mx[j]] = $D[mx[j].substring(0, 3)] = mf(j);
|
401
|
+
}
|
402
|
+
var ef = function(j) {
|
403
|
+
return function() {
|
404
|
+
if (j.substring(j.length - 1) != "s") {
|
405
|
+
j += "s";
|
406
|
+
}
|
407
|
+
return this["add" + j](this._orient);
|
408
|
+
};
|
409
|
+
};
|
410
|
+
var nf = function(n) {
|
411
|
+
return function() {
|
412
|
+
this._dateElement = n;
|
413
|
+
return this;
|
414
|
+
};
|
415
|
+
};
|
416
|
+
for (var k = 0; k < px.length; k++) {
|
417
|
+
de = px[k].toLowerCase();
|
418
|
+
$D[de] = $D[de + "s"] = ef(px[k]);
|
419
|
+
$N[de] = $N[de + "s"] = nf(de);
|
420
|
+
}
|
421
|
+
}());
|
422
|
+
Date.prototype.toJSONString = function() {
|
423
|
+
return this.toString("yyyy-MM-ddThh:mm:ssZ");
|
424
|
+
};
|
425
|
+
Date.prototype.toShortDateString = function() {
|
426
|
+
return this.toString(Date.CultureInfo.formatPatterns.shortDatePattern);
|
427
|
+
};
|
428
|
+
Date.prototype.toLongDateString = function() {
|
429
|
+
return this.toString(Date.CultureInfo.formatPatterns.longDatePattern);
|
430
|
+
};
|
431
|
+
Date.prototype.toShortTimeString = function() {
|
432
|
+
return this.toString(Date.CultureInfo.formatPatterns.shortTimePattern);
|
433
|
+
};
|
434
|
+
Date.prototype.toLongTimeString = function() {
|
435
|
+
return this.toString(Date.CultureInfo.formatPatterns.longTimePattern);
|
436
|
+
};
|
437
|
+
Date.prototype.getOrdinal = function() {
|
438
|
+
switch (this.getDate()) {
|
439
|
+
case 1:
|
440
|
+
case 21:
|
441
|
+
case 31:
|
442
|
+
return"st";
|
443
|
+
case 2:
|
444
|
+
case 22:
|
445
|
+
return"nd";
|
446
|
+
case 3:
|
447
|
+
case 23:
|
448
|
+
return"rd";
|
449
|
+
default:
|
450
|
+
return"th";
|
451
|
+
}
|
452
|
+
};
|
453
|
+
(function() {
|
454
|
+
Date.Parsing = {Exception:function(s) {
|
455
|
+
this.message = "Parse error at '" + s.substring(0, 10) + " ...'";
|
456
|
+
}};
|
457
|
+
var $P = Date.Parsing;
|
458
|
+
var _ = $P.Operators = {rtoken:function(r) {
|
459
|
+
return function(s) {
|
460
|
+
var mx = s.match(r);
|
461
|
+
if (mx) {
|
462
|
+
return([mx[0],s.substring(mx[0].length)]);
|
463
|
+
} else {
|
464
|
+
throw new $P.Exception(s);
|
465
|
+
}
|
466
|
+
};
|
467
|
+
},token:function(s) {
|
468
|
+
return function(s) {
|
469
|
+
return _.rtoken(new RegExp("^\s*" + s + "\s*"))(s);
|
470
|
+
};
|
471
|
+
},stoken:function(s) {
|
472
|
+
return _.rtoken(new RegExp("^" + s));
|
473
|
+
},until:function(p) {
|
474
|
+
return function(s) {
|
475
|
+
var qx = [],rx = null;
|
476
|
+
while (s.length) {
|
477
|
+
try {
|
478
|
+
rx = p.call(this, s);
|
479
|
+
} catch(e) {
|
480
|
+
qx.push(rx[0]);
|
481
|
+
s = rx[1];
|
482
|
+
continue;
|
483
|
+
}
|
484
|
+
break;
|
485
|
+
}
|
486
|
+
return[qx,s];
|
487
|
+
};
|
488
|
+
},many:function(p) {
|
489
|
+
return function(s) {
|
490
|
+
var rx = [],r = null;
|
491
|
+
while (s.length) {
|
492
|
+
try {
|
493
|
+
r = p.call(this, s);
|
494
|
+
} catch(e) {
|
495
|
+
return[rx,s];
|
496
|
+
}
|
497
|
+
rx.push(r[0]);
|
498
|
+
s = r[1];
|
499
|
+
}
|
500
|
+
return[rx,s];
|
501
|
+
};
|
502
|
+
},optional:function(p) {
|
503
|
+
return function(s) {
|
504
|
+
var r = null;
|
505
|
+
try {
|
506
|
+
r = p.call(this, s);
|
507
|
+
} catch(e) {
|
508
|
+
return[null,s];
|
509
|
+
}
|
510
|
+
return[r[0],r[1]];
|
511
|
+
};
|
512
|
+
},not:function(p) {
|
513
|
+
return function(s) {
|
514
|
+
try {
|
515
|
+
p.call(this, s);
|
516
|
+
} catch(e) {
|
517
|
+
return[null,s];
|
518
|
+
}
|
519
|
+
throw new $P.Exception(s);
|
520
|
+
};
|
521
|
+
},ignore:function(p) {
|
522
|
+
return p ? function(s) {
|
523
|
+
var r = null;
|
524
|
+
r = p.call(this, s);
|
525
|
+
return[null,r[1]];
|
526
|
+
} : null;
|
527
|
+
},product:function() {
|
528
|
+
var px = arguments[0],qx = Array.prototype.slice.call(arguments, 1),rx = [];
|
529
|
+
for (var i = 0; i < px.length; i++) {
|
530
|
+
rx.push(_.each(px[i], qx));
|
531
|
+
}
|
532
|
+
return rx;
|
533
|
+
},cache:function(rule) {
|
534
|
+
var cache = {},r = null;
|
535
|
+
return function(s) {
|
536
|
+
try {
|
537
|
+
r = cache[s] = (cache[s] || rule.call(this, s));
|
538
|
+
} catch(e) {
|
539
|
+
r = cache[s] = e;
|
540
|
+
}
|
541
|
+
if (r instanceof $P.Exception) {
|
542
|
+
throw r;
|
543
|
+
} else {
|
544
|
+
return r;
|
545
|
+
}
|
546
|
+
};
|
547
|
+
},any:function() {
|
548
|
+
var px = arguments;
|
549
|
+
return function(s) {
|
550
|
+
var r = null;
|
551
|
+
for (var i = 0; i < px.length; i++) {
|
552
|
+
if (px[i] == null) {
|
553
|
+
continue;
|
554
|
+
}
|
555
|
+
try {
|
556
|
+
r = (px[i].call(this, s));
|
557
|
+
} catch(e) {
|
558
|
+
r = null;
|
559
|
+
}
|
560
|
+
if (r) {
|
561
|
+
return r;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
throw new $P.Exception(s);
|
565
|
+
};
|
566
|
+
},each:function() {
|
567
|
+
var px = arguments;
|
568
|
+
return function(s) {
|
569
|
+
var rx = [],r = null;
|
570
|
+
for (var i = 0; i < px.length; i++) {
|
571
|
+
if (px[i] == null) {
|
572
|
+
continue;
|
573
|
+
}
|
574
|
+
try {
|
575
|
+
r = (px[i].call(this, s));
|
576
|
+
} catch(e) {
|
577
|
+
throw new $P.Exception(s);
|
578
|
+
}
|
579
|
+
rx.push(r[0]);
|
580
|
+
s = r[1];
|
581
|
+
}
|
582
|
+
return[rx,s];
|
583
|
+
};
|
584
|
+
},all:function() {
|
585
|
+
var px = arguments,_ = _;
|
586
|
+
return _.each(_.optional(px));
|
587
|
+
},sequence:function(px, d, c) {
|
588
|
+
d = d || _.rtoken(/^\s*/);
|
589
|
+
c = c || null;
|
590
|
+
if (px.length == 1) {
|
591
|
+
return px[0];
|
592
|
+
}
|
593
|
+
return function(s) {
|
594
|
+
var r = null,q = null;
|
595
|
+
var rx = [];
|
596
|
+
for (var i = 0; i < px.length; i++) {
|
597
|
+
try {
|
598
|
+
r = px[i].call(this, s);
|
599
|
+
} catch(e) {
|
600
|
+
break;
|
601
|
+
}
|
602
|
+
rx.push(r[0]);
|
603
|
+
try {
|
604
|
+
q = d.call(this, r[1]);
|
605
|
+
} catch(ex) {
|
606
|
+
q = null;
|
607
|
+
break;
|
608
|
+
}
|
609
|
+
s = q[1];
|
610
|
+
}
|
611
|
+
if (!r) {
|
612
|
+
throw new $P.Exception(s);
|
613
|
+
}
|
614
|
+
if (q) {
|
615
|
+
throw new $P.Exception(q[1]);
|
616
|
+
}
|
617
|
+
if (c) {
|
618
|
+
try {
|
619
|
+
r = c.call(this, r[1]);
|
620
|
+
} catch(ey) {
|
621
|
+
throw new $P.Exception(r[1]);
|
622
|
+
}
|
623
|
+
}
|
624
|
+
return[rx,(r ? r[1] : s)];
|
625
|
+
};
|
626
|
+
},between:function(d1, p, d2) {
|
627
|
+
d2 = d2 || d1;
|
628
|
+
var _fn = _.each(_.ignore(d1), p, _.ignore(d2));
|
629
|
+
return function(s) {
|
630
|
+
var rx = _fn.call(this, s);
|
631
|
+
return[
|
632
|
+
[rx[0][0],r[0][2]],
|
633
|
+
rx[1]
|
634
|
+
];
|
635
|
+
};
|
636
|
+
},list:function(p, d, c) {
|
637
|
+
d = d || _.rtoken(/^\s*/);
|
638
|
+
c = c || null;
|
639
|
+
return(p instanceof Array ? _.each(_.product(p.slice(0, -1), _.ignore(d)), p.slice(-1), _.ignore(c)) : _.each(_.many(_.each(p, _.ignore(d))), px, _.ignore(c)));
|
640
|
+
},set:function(px, d, c) {
|
641
|
+
d = d || _.rtoken(/^\s*/);
|
642
|
+
c = c || null;
|
643
|
+
return function(s) {
|
644
|
+
var r = null,p = null,q = null,rx = null,best = [
|
645
|
+
[],
|
646
|
+
s
|
647
|
+
],last = false;
|
648
|
+
for (var i = 0; i < px.length; i++) {
|
649
|
+
q = null;
|
650
|
+
p = null;
|
651
|
+
r = null;
|
652
|
+
last = (px.length == 1);
|
653
|
+
try {
|
654
|
+
r = px[i].call(this, s);
|
655
|
+
} catch(e) {
|
656
|
+
continue;
|
657
|
+
}
|
658
|
+
rx = [
|
659
|
+
[r[0]],
|
660
|
+
r[1]
|
661
|
+
];
|
662
|
+
if (r[1].length > 0 && !last) {
|
663
|
+
try {
|
664
|
+
q = d.call(this, r[1]);
|
665
|
+
} catch(ex) {
|
666
|
+
last = true;
|
667
|
+
}
|
668
|
+
} else {
|
669
|
+
last = true;
|
670
|
+
}
|
671
|
+
if (!last && q[1].length === 0) {
|
672
|
+
last = true;
|
673
|
+
}
|
674
|
+
if (!last) {
|
675
|
+
var qx = [];
|
676
|
+
for (var j = 0; j < px.length; j++) {
|
677
|
+
if (i != j) {
|
678
|
+
qx.push(px[j]);
|
679
|
+
}
|
680
|
+
}
|
681
|
+
p = _.set(qx, d).call(this, q[1]);
|
682
|
+
if (p[0].length > 0) {
|
683
|
+
rx[0] = rx[0].concat(p[0]);
|
684
|
+
rx[1] = p[1];
|
685
|
+
}
|
686
|
+
}
|
687
|
+
if (rx[1].length < best[1].length) {
|
688
|
+
best = rx;
|
689
|
+
}
|
690
|
+
if (best[1].length === 0) {
|
691
|
+
break;
|
692
|
+
}
|
693
|
+
}
|
694
|
+
if (best[0].length === 0) {
|
695
|
+
return best;
|
696
|
+
}
|
697
|
+
if (c) {
|
698
|
+
try {
|
699
|
+
q = c.call(this, best[1]);
|
700
|
+
} catch(ey) {
|
701
|
+
throw new $P.Exception(best[1]);
|
702
|
+
}
|
703
|
+
best[1] = q[1];
|
704
|
+
}
|
705
|
+
return best;
|
706
|
+
};
|
707
|
+
},forward:function(gr, fname) {
|
708
|
+
return function(s) {
|
709
|
+
return gr[fname].call(this, s);
|
710
|
+
};
|
711
|
+
},replace:function(rule, repl) {
|
712
|
+
return function(s) {
|
713
|
+
var r = rule.call(this, s);
|
714
|
+
return[repl,r[1]];
|
715
|
+
};
|
716
|
+
},process:function(rule, fn) {
|
717
|
+
return function(s) {
|
718
|
+
var r = rule.call(this, s);
|
719
|
+
return[fn.call(this, r[0]),r[1]];
|
720
|
+
};
|
721
|
+
},min:function(min, rule) {
|
722
|
+
return function(s) {
|
723
|
+
var rx = rule.call(this, s);
|
724
|
+
if (rx[0].length < min) {
|
725
|
+
throw new $P.Exception(s);
|
726
|
+
}
|
727
|
+
return rx;
|
728
|
+
};
|
729
|
+
}};
|
730
|
+
var _generator = function(op) {
|
731
|
+
return function() {
|
732
|
+
var args = null,rx = [];
|
733
|
+
if (arguments.length > 1) {
|
734
|
+
args = Array.prototype.slice.call(arguments);
|
735
|
+
} else if (arguments[0]instanceof Array) {
|
736
|
+
args = arguments[0];
|
737
|
+
}
|
738
|
+
if (args) {
|
739
|
+
for (var i = 0,px = args.shift(); i < px.length; i++) {
|
740
|
+
args.unshift(px[i]);
|
741
|
+
rx.push(op.apply(null, args));
|
742
|
+
args.shift();
|
743
|
+
return rx;
|
744
|
+
}
|
745
|
+
} else {
|
746
|
+
return op.apply(null, arguments);
|
747
|
+
}
|
748
|
+
};
|
749
|
+
};
|
750
|
+
var gx = "optional not ignore cache".split(/\s/);
|
751
|
+
for (var i = 0; i < gx.length; i++) {
|
752
|
+
_[gx[i]] = _generator(_[gx[i]]);
|
753
|
+
}
|
754
|
+
var _vector = function(op) {
|
755
|
+
return function() {
|
756
|
+
if (arguments[0]instanceof Array) {
|
757
|
+
return op.apply(null, arguments[0]);
|
758
|
+
} else {
|
759
|
+
return op.apply(null, arguments);
|
760
|
+
}
|
761
|
+
};
|
762
|
+
};
|
763
|
+
var vx = "each any all".split(/\s/);
|
764
|
+
for (var j = 0; j < vx.length; j++) {
|
765
|
+
_[vx[j]] = _vector(_[vx[j]]);
|
766
|
+
}
|
767
|
+
}());
|
768
|
+
(function() {
|
769
|
+
var flattenAndCompact = function(ax) {
|
770
|
+
var rx = [];
|
771
|
+
for (var i = 0; i < ax.length; i++) {
|
772
|
+
if (ax[i]instanceof Array) {
|
773
|
+
rx = rx.concat(flattenAndCompact(ax[i]));
|
774
|
+
} else {
|
775
|
+
if (ax[i]) {
|
776
|
+
rx.push(ax[i]);
|
777
|
+
}
|
778
|
+
}
|
779
|
+
}
|
780
|
+
return rx;
|
781
|
+
};
|
782
|
+
Date.Grammar = {};
|
783
|
+
Date.Translator = {hour:function(s) {
|
784
|
+
return function() {
|
785
|
+
this.hour = Number(s);
|
786
|
+
};
|
787
|
+
},minute:function(s) {
|
788
|
+
return function() {
|
789
|
+
this.minute = Number(s);
|
790
|
+
};
|
791
|
+
},second:function(s) {
|
792
|
+
return function() {
|
793
|
+
this.second = Number(s);
|
794
|
+
};
|
795
|
+
},meridian:function(s) {
|
796
|
+
return function() {
|
797
|
+
this.meridian = s.slice(0, 1).toLowerCase();
|
798
|
+
};
|
799
|
+
},timezone:function(s) {
|
800
|
+
return function() {
|
801
|
+
var n = s.replace(/[^\d\+\-]/g, "");
|
802
|
+
if (n.length) {
|
803
|
+
this.timezoneOffset = Number(n);
|
804
|
+
} else {
|
805
|
+
this.timezone = s.toLowerCase();
|
806
|
+
}
|
807
|
+
};
|
808
|
+
},day:function(x) {
|
809
|
+
var s = x[0];
|
810
|
+
return function() {
|
811
|
+
this.day = Number(s.match(/\d+/)[0]);
|
812
|
+
};
|
813
|
+
},month:function(s) {
|
814
|
+
return function() {
|
815
|
+
this.month = ((s.length == 3) ? Date.getMonthNumberFromName(s) : (Number(s) - 1));
|
816
|
+
};
|
817
|
+
},year:function(s) {
|
818
|
+
return function() {
|
819
|
+
var n = Number(s);
|
820
|
+
this.year = ((s.length > 2) ? n : (n + (((n + 2000) < Date.CultureInfo.twoDigitYearMax) ? 2000 : 1900)));
|
821
|
+
};
|
822
|
+
},rday:function(s) {
|
823
|
+
return function() {
|
824
|
+
switch (s) {
|
825
|
+
case"yesterday":
|
826
|
+
this.days = -1;
|
827
|
+
break;
|
828
|
+
case"tomorrow":
|
829
|
+
this.days = 1;
|
830
|
+
break;
|
831
|
+
case"today":
|
832
|
+
this.days = 0;
|
833
|
+
break;
|
834
|
+
case"now":
|
835
|
+
this.days = 0;
|
836
|
+
this.now = true;
|
837
|
+
break;
|
838
|
+
}
|
839
|
+
};
|
840
|
+
},finishExact:function(x) {
|
841
|
+
x = (x instanceof Array) ? x : [x];
|
842
|
+
var now = new Date();
|
843
|
+
this.year = now.getFullYear();
|
844
|
+
this.month = now.getMonth();
|
845
|
+
this.day = 1;
|
846
|
+
this.hour = 0;
|
847
|
+
this.minute = 0;
|
848
|
+
this.second = 0;
|
849
|
+
for (var i = 0; i < x.length; i++) {
|
850
|
+
if (x[i]) {
|
851
|
+
x[i].call(this);
|
852
|
+
}
|
853
|
+
}
|
854
|
+
this.hour = (this.meridian == "p" && this.hour < 13) ? this.hour + 12 : this.hour;
|
855
|
+
if (this.day > Date.getDaysInMonth(this.year, this.month)) {
|
856
|
+
throw new RangeError(this.day + " is not a valid value for days.");
|
857
|
+
}
|
858
|
+
var r = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second);
|
859
|
+
if (this.timezone) {
|
860
|
+
r.set({timezone:this.timezone});
|
861
|
+
} else if (this.timezoneOffset) {
|
862
|
+
r.set({timezoneOffset:this.timezoneOffset});
|
863
|
+
}
|
864
|
+
return r;
|
865
|
+
},finish:function(x) {
|
866
|
+
x = (x instanceof Array) ? flattenAndCompact(x) : [x];
|
867
|
+
if (x.length === 0) {
|
868
|
+
return null;
|
869
|
+
}
|
870
|
+
for (var i = 0; i < x.length; i++) {
|
871
|
+
if (typeof x[i] == "function") {
|
872
|
+
x[i].call(this);
|
873
|
+
}
|
874
|
+
}
|
875
|
+
if (this.now) {
|
876
|
+
return new Date();
|
877
|
+
}
|
878
|
+
var today = Date.today();
|
879
|
+
var method = null;
|
880
|
+
var expression = !!(this.days != null || this.orient || this.operator);
|
881
|
+
if (expression) {
|
882
|
+
var gap,mod,orient;
|
883
|
+
orient = ((this.orient == "past" || this.operator == "subtract") ? -1 : 1);
|
884
|
+
if (this.weekday) {
|
885
|
+
this.unit = "day";
|
886
|
+
gap = (Date.getDayNumberFromName(this.weekday) - today.getDay());
|
887
|
+
mod = 7;
|
888
|
+
this.days = gap ? ((gap + (orient * mod)) % mod) : (orient * mod);
|
889
|
+
}
|
890
|
+
if (this.month) {
|
891
|
+
this.unit = "month";
|
892
|
+
gap = (this.month - today.getMonth());
|
893
|
+
mod = 12;
|
894
|
+
this.months = gap ? ((gap + (orient * mod)) % mod) : (orient * mod);
|
895
|
+
this.month = null;
|
896
|
+
}
|
897
|
+
if (!this.unit) {
|
898
|
+
this.unit = "day";
|
899
|
+
}
|
900
|
+
if (this[this.unit + "s"] == null || this.operator != null) {
|
901
|
+
if (!this.value) {
|
902
|
+
this.value = 1;
|
903
|
+
}
|
904
|
+
if (this.unit == "week") {
|
905
|
+
this.unit = "day";
|
906
|
+
this.value = this.value * 7;
|
907
|
+
}
|
908
|
+
this[this.unit + "s"] = this.value * orient;
|
909
|
+
}
|
910
|
+
return today.add(this);
|
911
|
+
} else {
|
912
|
+
if (this.meridian && this.hour) {
|
913
|
+
this.hour = (this.hour < 13 && this.meridian == "p") ? this.hour + 12 : this.hour;
|
914
|
+
}
|
915
|
+
if (this.weekday && !this.day) {
|
916
|
+
this.day = (today.addDays((Date.getDayNumberFromName(this.weekday) - today.getDay()))).getDate();
|
917
|
+
}
|
918
|
+
if (this.month && !this.day) {
|
919
|
+
this.day = 1;
|
920
|
+
}
|
921
|
+
return today.set(this);
|
922
|
+
}
|
923
|
+
}};
|
924
|
+
var _ = Date.Parsing.Operators,g = Date.Grammar,t = Date.Translator,_fn;
|
925
|
+
g.datePartDelimiter = _.rtoken(/^([\s\-\.\,\/\x27]+)/);
|
926
|
+
g.timePartDelimiter = _.stoken(":");
|
927
|
+
g.whiteSpace = _.rtoken(/^\s*/);
|
928
|
+
g.generalDelimiter = _.rtoken(/^(([\s\,]|at|on)+)/);
|
929
|
+
var _C = {};
|
930
|
+
g.ctoken = function(keys) {
|
931
|
+
var fn = _C[keys];
|
932
|
+
if (!fn) {
|
933
|
+
var c = Date.CultureInfo.regexPatterns;
|
934
|
+
var kx = keys.split(/\s+/),px = [];
|
935
|
+
for (var i = 0; i < kx.length; i++) {
|
936
|
+
px.push(_.replace(_.rtoken(c[kx[i]]), kx[i]));
|
937
|
+
}
|
938
|
+
fn = _C[keys] = _.any.apply(null, px);
|
939
|
+
}
|
940
|
+
return fn;
|
941
|
+
};
|
942
|
+
g.ctoken2 = function(key) {
|
943
|
+
return _.rtoken(Date.CultureInfo.regexPatterns[key]);
|
944
|
+
};
|
945
|
+
g.h = _.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2]|[1-9])/), t.hour));
|
946
|
+
g.hh = _.cache(_.process(_.rtoken(/^(0[0-9]|1[0-2])/), t.hour));
|
947
|
+
g.H = _.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3]|[0-9])/), t.hour));
|
948
|
+
g.HH = _.cache(_.process(_.rtoken(/^([0-1][0-9]|2[0-3])/), t.hour));
|
949
|
+
g.m = _.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/), t.minute));
|
950
|
+
g.mm = _.cache(_.process(_.rtoken(/^[0-5][0-9]/), t.minute));
|
951
|
+
g.s = _.cache(_.process(_.rtoken(/^([0-5][0-9]|[0-9])/), t.second));
|
952
|
+
g.ss = _.cache(_.process(_.rtoken(/^[0-5][0-9]/), t.second));
|
953
|
+
g.hms = _.cache(_.sequence([g.H,g.mm,g.ss], g.timePartDelimiter));
|
954
|
+
g.t = _.cache(_.process(g.ctoken2("shortMeridian"), t.meridian));
|
955
|
+
g.tt = _.cache(_.process(g.ctoken2("longMeridian"), t.meridian));
|
956
|
+
g.z = _.cache(_.process(_.rtoken(/^(\+|\-)?\s*\d\d\d\d?/), t.timezone));
|
957
|
+
g.zz = _.cache(_.process(_.rtoken(/^(\+|\-)\s*\d\d\d\d/), t.timezone));
|
958
|
+
g.zzz = _.cache(_.process(g.ctoken2("timezone"), t.timezone));
|
959
|
+
g.timeSuffix = _.each(_.ignore(g.whiteSpace), _.set([g.tt,g.zzz]));
|
960
|
+
g.time = _.each(_.optional(_.ignore(_.stoken("T"))), g.hms, g.timeSuffix);
|
961
|
+
g.d = _.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1]|\d)/), _.optional(g.ctoken2("ordinalSuffix"))), t.day));
|
962
|
+
g.dd = _.cache(_.process(_.each(_.rtoken(/^([0-2]\d|3[0-1])/), _.optional(g.ctoken2("ordinalSuffix"))), t.day));
|
963
|
+
g.ddd = g.dddd = _.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"), function(s) {
|
964
|
+
return function() {
|
965
|
+
this.weekday = s;
|
966
|
+
};
|
967
|
+
}));
|
968
|
+
g.M = _.cache(_.process(_.rtoken(/^(1[0-2]|0\d|\d)/), t.month));
|
969
|
+
g.MM = _.cache(_.process(_.rtoken(/^(1[0-2]|0\d)/), t.month));
|
970
|
+
g.MMM = g.MMMM = _.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"), t.month));
|
971
|
+
g.y = _.cache(_.process(_.rtoken(/^(\d\d?)/), t.year));
|
972
|
+
g.yy = _.cache(_.process(_.rtoken(/^(\d\d)/), t.year));
|
973
|
+
g.yyy = _.cache(_.process(_.rtoken(/^(\d\d?\d?\d?)/), t.year));
|
974
|
+
g.yyyy = _.cache(_.process(_.rtoken(/^(\d\d\d\d)/), t.year));
|
975
|
+
_fn = function() {
|
976
|
+
return _.each(_.any.apply(null, arguments), _.not(g.ctoken2("timeContext")));
|
977
|
+
};
|
978
|
+
g.day = _fn(g.d, g.dd);
|
979
|
+
g.month = _fn(g.M, g.MMM);
|
980
|
+
g.year = _fn(g.yyyy, g.yy);
|
981
|
+
g.orientation = _.process(g.ctoken("past future"), function(s) {
|
982
|
+
return function() {
|
983
|
+
this.orient = s;
|
984
|
+
};
|
985
|
+
});
|
986
|
+
g.operator = _.process(g.ctoken("add subtract"), function(s) {
|
987
|
+
return function() {
|
988
|
+
this.operator = s;
|
989
|
+
};
|
990
|
+
});
|
991
|
+
g.rday = _.process(g.ctoken("yesterday tomorrow today now"), t.rday);
|
992
|
+
g.unit = _.process(g.ctoken("minute hour day week month year"), function(s) {
|
993
|
+
return function() {
|
994
|
+
this.unit = s;
|
995
|
+
};
|
996
|
+
});
|
997
|
+
g.value = _.process(_.rtoken(/^\d\d?(st|nd|rd|th)?/), function(s) {
|
998
|
+
return function() {
|
999
|
+
this.value = s.replace(/\D/g, "");
|
1000
|
+
};
|
1001
|
+
});
|
1002
|
+
g.expression = _.set([g.rday,g.operator,g.value,g.unit,g.orientation,g.ddd,g.MMM]);
|
1003
|
+
_fn = function() {
|
1004
|
+
return _.set(arguments, g.datePartDelimiter);
|
1005
|
+
};
|
1006
|
+
g.mdy = _fn(g.ddd, g.month, g.day, g.year);
|
1007
|
+
g.ymd = _fn(g.ddd, g.year, g.month, g.day);
|
1008
|
+
g.dmy = _fn(g.ddd, g.day, g.month, g.year);
|
1009
|
+
g.date = function(s) {
|
1010
|
+
return((g[Date.CultureInfo.dateElementOrder] || g.mdy).call(this, s));
|
1011
|
+
};
|
1012
|
+
g.format = _.process(_.many(_.any(_.process(_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/), function(fmt) {
|
1013
|
+
if (g[fmt]) {
|
1014
|
+
return g[fmt];
|
1015
|
+
} else {
|
1016
|
+
throw Date.Parsing.Exception(fmt);
|
1017
|
+
}
|
1018
|
+
}), _.process(_.rtoken(/^[^dMyhHmstz]+/), function(s) {
|
1019
|
+
return _.ignore(_.stoken(s));
|
1020
|
+
}))), function(rules) {
|
1021
|
+
return _.process(_.each.apply(null, rules), t.finishExact);
|
1022
|
+
});
|
1023
|
+
var _F = {};
|
1024
|
+
var _get = function(f) {
|
1025
|
+
return _F[f] = (_F[f] || g.format(f)[0]);
|
1026
|
+
};
|
1027
|
+
g.formats = function(fx) {
|
1028
|
+
if (fx instanceof Array) {
|
1029
|
+
var rx = [];
|
1030
|
+
for (var i = 0; i < fx.length; i++) {
|
1031
|
+
rx.push(_get(fx[i]));
|
1032
|
+
}
|
1033
|
+
return _.any.apply(null, rx);
|
1034
|
+
} else {
|
1035
|
+
return _get(fx);
|
1036
|
+
}
|
1037
|
+
};
|
1038
|
+
g._formats = g.formats(["yyyy-MM-ddTHH:mm:ss","ddd, MMM dd, yyyy H:mm:ss tt","ddd MMM d yyyy HH:mm:ss zzz","d"]);
|
1039
|
+
g._start = _.process(_.set([g.date,g.time,g.expression], g.generalDelimiter, g.whiteSpace), t.finish);
|
1040
|
+
g.start = function(s) {
|
1041
|
+
try {
|
1042
|
+
var r = g._formats.call({}, s);
|
1043
|
+
if (r[1].length === 0) {
|
1044
|
+
return r;
|
1045
|
+
}
|
1046
|
+
} catch(e) {
|
1047
|
+
}
|
1048
|
+
return g._start.call({}, s);
|
1049
|
+
};
|
1050
|
+
}());
|
1051
|
+
Date._parse = Date.parse;
|
1052
|
+
Date.parse = function(s) {
|
1053
|
+
var r = null;
|
1054
|
+
if (!s) {
|
1055
|
+
return null;
|
1056
|
+
}
|
1057
|
+
try {
|
1058
|
+
r = Date.Grammar.start.call({}, s);
|
1059
|
+
} catch(e) {
|
1060
|
+
return null;
|
1061
|
+
}
|
1062
|
+
return((r[1].length === 0) ? r[0] : null);
|
1063
|
+
};
|
1064
|
+
Date.getParseFunction = function(fx) {
|
1065
|
+
var fn = Date.Grammar.formats(fx);
|
1066
|
+
return function(s) {
|
1067
|
+
var r = null;
|
1068
|
+
try {
|
1069
|
+
r = fn.call({}, s);
|
1070
|
+
} catch(e) {
|
1071
|
+
return null;
|
1072
|
+
}
|
1073
|
+
return((r[1].length === 0) ? r[0] : null);
|
1074
|
+
};
|
1075
|
+
};
|
1076
|
+
Date.parseExact = function(s, fx) {
|
1077
|
+
return Date.getParseFunction(fx)(s);
|
1078
|
+
};
|