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