1 |
|
2 |
|
3 |
|
4 | export var ALL_WEEKDAYS = [
|
5 | 'MO',
|
6 | 'TU',
|
7 | 'WE',
|
8 | 'TH',
|
9 | 'FR',
|
10 | 'SA',
|
11 | 'SU',
|
12 | ];
|
13 | var Weekday = (function () {
|
14 | function Weekday(weekday, n) {
|
15 | if (n === 0)
|
16 | throw new Error("Can't create weekday with n == 0");
|
17 | this.weekday = weekday;
|
18 | this.n = n;
|
19 | }
|
20 | Weekday.fromStr = function (str) {
|
21 | return new Weekday(ALL_WEEKDAYS.indexOf(str));
|
22 | };
|
23 |
|
24 |
|
25 | Weekday.prototype.nth = function (n) {
|
26 | return this.n === n ? this : new Weekday(this.weekday, n);
|
27 | };
|
28 |
|
29 | Weekday.prototype.equals = function (other) {
|
30 | return this.weekday === other.weekday && this.n === other.n;
|
31 | };
|
32 |
|
33 | Weekday.prototype.toString = function () {
|
34 | var s = ALL_WEEKDAYS[this.weekday];
|
35 | if (this.n)
|
36 | s = (this.n > 0 ? '+' : '') + String(this.n) + s;
|
37 | return s;
|
38 | };
|
39 | Weekday.prototype.getJsWeekday = function () {
|
40 | return this.weekday === 6 ? 0 : this.weekday + 1;
|
41 | };
|
42 | return Weekday;
|
43 | }());
|
44 | export { Weekday };
|
45 |
|
\ | No newline at end of file |