1 | var ornellemberBundle=(function(exports){'use strict';var getDaysBeforeCurrentMonth = function (currentMonthIndex, isLeapYear) {
|
2 |
|
3 | var daysInMonths = [
|
4 | 31,
|
5 | isLeapYear ? 29 : 28,
|
6 | 31,
|
7 | 30,
|
8 | 31,
|
9 | 30,
|
10 | 31,
|
11 | 31,
|
12 | 30,
|
13 | 31,
|
14 | 30,
|
15 | 31
|
16 | ];
|
17 |
|
18 | var daysBeforeCurrentMonth = 0;
|
19 | for (var i = 0; i < currentMonthIndex; i++) {
|
20 | daysBeforeCurrentMonth += daysInMonths[i];
|
21 | }
|
22 | return daysBeforeCurrentMonth;
|
23 | };
|
24 | var isLeapYear = function (date) {
|
25 | return (date.getFullYear() % 4) === 0;
|
26 | };
|
27 | var getDayNumber = function (date) {
|
28 |
|
29 | var isCurrentLeapYear = isLeapYear(date);
|
30 | var currentMonth = date.getMonth();
|
31 |
|
32 | var daysBeforeCurrentMonth = getDaysBeforeCurrentMonth(currentMonth, isCurrentLeapYear);
|
33 | var dayOfMonth = date.getDate();
|
34 | return daysBeforeCurrentMonth + dayOfMonth;
|
35 | };
|
36 | var convertDay = function (dayNumber) {
|
37 | var monthLength = 28;
|
38 | var monthIndex = Math.floor((dayNumber - 1) / monthLength);
|
39 |
|
40 | if (monthIndex > 12) {
|
41 | monthIndex = 12;
|
42 | }
|
43 | var dayOfMonth = dayNumber - (monthIndex * monthLength);
|
44 | var monthLetter = String.fromCharCode(97 + monthIndex).toUpperCase();
|
45 | return {
|
46 | day: dayOfMonth,
|
47 | month: monthLetter
|
48 | };
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | var getOrnellemberDay = function (date) {
|
56 | var dayNumber = getDayNumber(date);
|
57 | return convertDay(dayNumber);
|
58 | }; |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | var addToDate = function (originalDate, quantity, unit) {
|
66 | var valueToAdd;
|
67 | switch (unit) {
|
68 | case 'seconds': {
|
69 | valueToAdd = quantity * 1000;
|
70 | break;
|
71 | }
|
72 | case 'minutes': {
|
73 | valueToAdd = quantity * 1000 * 60;
|
74 | break;
|
75 | }
|
76 | case 'hours': {
|
77 | valueToAdd = quantity * 1000 * 60 * 60;
|
78 | break;
|
79 | }
|
80 | case 'days': {
|
81 | valueToAdd = quantity * 1000 * 60 * 60 * 24;
|
82 | break;
|
83 | }
|
84 | case 'months': {
|
85 |
|
86 | if (getDayNumber(originalDate) >= (365 - 29)) {
|
87 | if (isLeapYear(originalDate)) {
|
88 | valueToAdd = quantity * 1000 * 60 * 60 * 24 * 30;
|
89 | }
|
90 | else {
|
91 | valueToAdd = quantity * 1000 * 60 * 60 * 24 * 29;
|
92 | }
|
93 | }
|
94 | else {
|
95 | valueToAdd = quantity * 1000 * 60 * 60 * 24 * 28;
|
96 | }
|
97 | break;
|
98 | }
|
99 | default: {
|
100 | valueToAdd = 0;
|
101 | break;
|
102 | }
|
103 | }
|
104 | var newDateValue = originalDate.valueOf() + valueToAdd;
|
105 | var newDate = new Date(newDateValue);
|
106 | if (unit === 'years') {
|
107 | newDate.setFullYear(originalDate.getFullYear() + quantity);
|
108 | }
|
109 | return newDate;
|
110 | };var Ornellember = (function () {
|
111 | function Ornellember(date) {
|
112 | var rawDate = date;
|
113 | var converted = getOrnellemberDay(rawDate);
|
114 | this.day = converted.day;
|
115 | this.month = converted.month;
|
116 | this.rawDate = rawDate;
|
117 | this.year = rawDate.getFullYear();
|
118 | this.hours = rawDate.getHours();
|
119 | this.minutes = rawDate.getMinutes();
|
120 | this.milliseconds = rawDate.getMilliseconds();
|
121 | }
|
122 | Ornellember.prototype.clone = function () {
|
123 | return new Ornellember(this.rawDate);
|
124 | };
|
125 | Ornellember.prototype.add = function (quantity, unit) {
|
126 | var newDate = addToDate(this.rawDate, quantity, unit);
|
127 | return new Ornellember(newDate);
|
128 | };
|
129 | Ornellember.prototype.format = function () {
|
130 | return this.day + " " + this.month + ", " + this.year;
|
131 | };
|
132 | Ornellember.prototype.holiday = function () {
|
133 | if (this.day === 29)
|
134 | return 'N';
|
135 | if (this.day === 30)
|
136 | return 'O';
|
137 | return null;
|
138 | };
|
139 | Ornellember.prototype.subtract = function (quantity, unit) {
|
140 | return this.add(-quantity, unit);
|
141 | };
|
142 | return Ornellember;
|
143 | }());
|
144 | var index = (function (date) {
|
145 | if (date instanceof Date) {
|
146 | return new Ornellember(date);
|
147 | }
|
148 | if (date instanceof Ornellember) {
|
149 | return date.clone();
|
150 | }
|
151 | if (!date) {
|
152 | return new Ornellember(new Date());
|
153 | }
|
154 | throw new Error('Unexpected input. Accepted types are a Date, an Ornellember instance, or undefined');
|
155 | });exports.Ornellember=Ornellember;exports["default"]=index;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({}); |
\ | No newline at end of file |