@odoo/o-spreadsheet 15.2.13 → 15.2.14

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.
@@ -128,14 +128,72 @@
128
128
  // -----------------------------------------------------------------------------
129
129
  // Date Type
130
130
  // -----------------------------------------------------------------------------
131
+ /**
132
+ * A DateTime object that can be used to manipulate spreadsheet dates.
133
+ * Conceptually, a spreadsheet date is simply a number with a date format,
134
+ * and it is timezone-agnostic.
135
+ * This DateTime object consistently uses UTC time to represent a naive date and time.
136
+ */
137
+ class DateTime {
138
+ constructor(year, month, day, hours = 0, minutes = 0, seconds = 0) {
139
+ this.jsDate = new Date(Date.UTC(year, month, day, hours, minutes, seconds, 0));
140
+ }
141
+ static fromTimestamp(timestamp) {
142
+ const date = new Date(timestamp);
143
+ return new DateTime(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
144
+ }
145
+ static now() {
146
+ const now = new Date();
147
+ return new DateTime(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
148
+ }
149
+ toString() {
150
+ return this.jsDate.toString();
151
+ }
152
+ getTime() {
153
+ return this.jsDate.getTime();
154
+ }
155
+ getFullYear() {
156
+ return this.jsDate.getUTCFullYear();
157
+ }
158
+ getMonth() {
159
+ return this.jsDate.getUTCMonth();
160
+ }
161
+ getDate() {
162
+ return this.jsDate.getUTCDate();
163
+ }
164
+ getDay() {
165
+ return this.jsDate.getUTCDay();
166
+ }
167
+ getHours() {
168
+ return this.jsDate.getUTCHours();
169
+ }
170
+ getMinutes() {
171
+ return this.jsDate.getUTCMinutes();
172
+ }
173
+ getSeconds() {
174
+ return this.jsDate.getUTCSeconds();
175
+ }
176
+ setDate(date) {
177
+ this.jsDate.setUTCDate(date);
178
+ }
179
+ setHours(hours) {
180
+ this.jsDate.setUTCHours(hours);
181
+ }
182
+ setMinutes(minutes) {
183
+ this.jsDate.setUTCMinutes(minutes);
184
+ }
185
+ setSeconds(seconds) {
186
+ this.jsDate.setUTCSeconds(seconds);
187
+ }
188
+ }
131
189
  // -----------------------------------------------------------------------------
132
190
  // Parsing
133
191
  // -----------------------------------------------------------------------------
134
192
  const CURRENT_MILLENIAL = 2000; // note: don't forget to update this in 2999
135
- const CURRENT_YEAR = new Date().getFullYear();
136
- const INITIAL_1900_DAY$1 = new Date(1899, 11, 30);
137
- const INITIAL_JS_DAY = new Date(0);
138
- const DATE_JS_1900_OFFSET = INITIAL_JS_DAY - INITIAL_1900_DAY$1;
193
+ const CURRENT_YEAR = DateTime.now().getFullYear();
194
+ const INITIAL_1900_DAY$1 = new DateTime(1899, 11, 30);
195
+ const INITIAL_JS_DAY = DateTime.fromTimestamp(0);
196
+ const DATE_JS_1900_OFFSET = INITIAL_JS_DAY.getTime() - INITIAL_1900_DAY$1.getTime();
139
197
  const mdyDateRegexp = /^\d{1,2}(\/|-|\s)\d{1,2}((\/|-|\s)\d{1,4})?$/;
140
198
  const ymdDateRegexp = /^\d{3,4}(\/|-|\s)\d{1,2}(\/|-|\s)\d{1,2}$/;
141
199
  const timeRegexp = /((\d+(:\d+)?(:\d+)?\s*(AM|PM))|(\d+:\d+(:\d+)?))$/;
@@ -175,7 +233,7 @@
175
233
  return {
176
234
  value: date.value + time.value,
177
235
  format: date.format + " " + (time.format === "hhhh:mm:ss" ? "hh:mm:ss" : time.format),
178
- jsDate: new Date(date.jsDate.getFullYear() + time.jsDate.getFullYear() - 1899, date.jsDate.getMonth() + time.jsDate.getMonth() - 11, date.jsDate.getDate() + time.jsDate.getDate() - 30, date.jsDate.getHours() + time.jsDate.getHours(), date.jsDate.getMinutes() + time.jsDate.getMinutes(), date.jsDate.getSeconds() + time.jsDate.getSeconds()),
236
+ jsDate: new DateTime(date.jsDate.getFullYear() + time.jsDate.getFullYear() - 1899, date.jsDate.getMonth() + time.jsDate.getMonth() - 11, date.jsDate.getDate() + time.jsDate.getDate() - 30, date.jsDate.getHours() + time.jsDate.getHours(), date.jsDate.getMinutes() + time.jsDate.getMinutes(), date.jsDate.getSeconds() + time.jsDate.getSeconds()),
179
237
  };
180
238
  }
181
239
  return date || time;
@@ -192,13 +250,13 @@
192
250
  const day = Number(parts[dayIndex]);
193
251
  const leadingZero = (parts[monthIndex].length === 2 && month < 10) || (parts[dayIndex].length === 2 && day < 10);
194
252
  const year = parts[yearIndex] ? inferYear(parts[yearIndex]) : CURRENT_YEAR;
195
- const jsDate = new Date(year, month - 1, day);
253
+ const jsDate = new DateTime(year, month - 1, day);
196
254
  const sep = str.match(/\/|-|\s/)[0];
197
255
  if (jsDate.getMonth() !== month - 1 || jsDate.getDate() !== day) {
198
256
  // invalid date
199
257
  return null;
200
258
  }
201
- const delta = jsDate - INITIAL_1900_DAY$1;
259
+ const delta = jsDate.getTime() - INITIAL_1900_DAY$1.getTime();
202
260
  let format = leadingZero ? `mm${sep}dd` : `m${sep}d`;
203
261
  if (parts[yearIndex]) {
204
262
  format = isMDY ? format + sep + "yyyy" : "yyyy" + sep + format;
@@ -258,7 +316,7 @@
258
316
  if (hours >= 24) {
259
317
  format = "hhhh:mm:ss";
260
318
  }
261
- const jsDate = new Date(1899, 11, 30, hours, minutes, seconds);
319
+ const jsDate = new DateTime(1899, 11, 30, hours, minutes, seconds);
262
320
  return {
263
321
  value: hours / 24 + minutes / 1440 + seconds / 86400,
264
322
  format: format,
@@ -272,7 +330,7 @@
272
330
  // -----------------------------------------------------------------------------
273
331
  function numberToJsDate(value) {
274
332
  const truncValue = Math.trunc(value);
275
- let date = new Date(truncValue * 86400 * 1000 - DATE_JS_1900_OFFSET);
333
+ let date = DateTime.fromTimestamp(truncValue * 86400 * 1000 - DATE_JS_1900_OFFSET);
276
334
  let time = value - truncValue;
277
335
  time = time < 0 ? 1 + time : time;
278
336
  const hours = Math.round(time * 24);
@@ -345,7 +403,7 @@
345
403
  .map((p) => {
346
404
  switch (p) {
347
405
  case "hhhh":
348
- const helapsedHours = Math.floor((jsDate.getTime() - INITIAL_1900_DAY$1) / (60 * 60 * 1000));
406
+ const helapsedHours = Math.floor((jsDate.getTime() - INITIAL_1900_DAY$1.getTime()) / (60 * 60 * 1000));
349
407
  return helapsedHours.toString();
350
408
  case "hh":
351
409
  return hours.toString().padStart(2, "0");
@@ -2864,7 +2922,7 @@
2864
2922
  function isDateTime(str) {
2865
2923
  return parseDateTime(str) !== null;
2866
2924
  }
2867
- const MARKDOWN_LINK_REGEX = /^\[([^\[]+)\]\((.+)\)$/;
2925
+ const MARKDOWN_LINK_REGEX = /^\[(.+)\]\((.+)\)$/;
2868
2926
  //link must start with http or https
2869
2927
  //https://stackoverflow.com/a/3809435/4760614
2870
2928
  const WEB_LINK_REGEX = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
@@ -4740,7 +4798,7 @@
4740
4798
  DVARP: DVARP
4741
4799
  });
4742
4800
 
4743
- const INITIAL_1900_DAY = new Date(1899, 11, 30);
4801
+ const INITIAL_1900_DAY = new DateTime(1899, 11, 30);
4744
4802
  const DEFAULT_TYPE = 1;
4745
4803
  const DEFAULT_WEEKEND = 1;
4746
4804
  function isLeapYear(year) {
@@ -4769,7 +4827,7 @@
4769
4827
  if (_year < 1900) {
4770
4828
  _year += 1900;
4771
4829
  }
4772
- const jsDate = new Date(_year, _month - 1, _day);
4830
+ const jsDate = new DateTime(_year, _month - 1, _day);
4773
4831
  const delta = jsDate.getTime() - INITIAL_1900_DAY.getTime();
4774
4832
  assert(() => delta >= 0, _lt(`The function [[FUNCTION_NAME]] result must be greater than or equal 01/01/1900.`));
4775
4833
  return Math.round(delta / 86400000);
@@ -4842,7 +4900,7 @@
4842
4900
  const yStart = _startDate.getFullYear();
4843
4901
  const mStart = _startDate.getMonth();
4844
4902
  const dStart = _startDate.getDate();
4845
- const jsDate = new Date(yStart, mStart + _months, dStart);
4903
+ const jsDate = new DateTime(yStart, mStart + _months, dStart);
4846
4904
  const delta = jsDate.getTime() - INITIAL_1900_DAY.getTime();
4847
4905
  return Math.round(delta / 86400000);
4848
4906
  },
@@ -4864,7 +4922,7 @@
4864
4922
  const _months = Math.trunc(toNumber(months));
4865
4923
  const yStart = _startDate.getFullYear();
4866
4924
  const mStart = _startDate.getMonth();
4867
- const jsDate = new Date(yStart, mStart + _months + 1, 0);
4925
+ const jsDate = new DateTime(yStart, mStart + _months + 1, 0);
4868
4926
  const delta = jsDate.getTime() - INITIAL_1900_DAY.getTime();
4869
4927
  return Math.round(delta / 86400000);
4870
4928
  },
@@ -4904,17 +4962,17 @@
4904
4962
  // The first week of the year is the week that contains the first
4905
4963
  // Thursday of the year.
4906
4964
  let firstThursday = 1;
4907
- while (new Date(y, 0, firstThursday).getDay() !== 4) {
4965
+ while (new DateTime(y, 0, firstThursday).getDay() !== 4) {
4908
4966
  firstThursday += 1;
4909
4967
  }
4910
- const firstDayOfFirstWeek = new Date(y, 0, firstThursday - 3);
4968
+ const firstDayOfFirstWeek = new DateTime(y, 0, firstThursday - 3);
4911
4969
  // The last week of the year is the week that contains the last Thursday of
4912
4970
  // the year.
4913
4971
  let lastThursday = 31;
4914
- while (new Date(y, 11, lastThursday).getDay() !== 4) {
4972
+ while (new DateTime(y, 11, lastThursday).getDay() !== 4) {
4915
4973
  lastThursday -= 1;
4916
4974
  }
4917
- const lastDayOfLastWeek = new Date(y, 11, lastThursday + 3);
4975
+ const lastDayOfLastWeek = new DateTime(y, 11, lastThursday + 3);
4918
4976
  // B - If our date > lastDayOfLastWeek then it's in the weeks of the year after
4919
4977
  // If our date < firstDayOfFirstWeek then it's in the weeks of the year before
4920
4978
  let offsetYear;
@@ -4940,17 +4998,17 @@
4940
4998
  case 1:
4941
4999
  // firstDay is the 1st day of the 1st week of the year after
4942
5000
  // firstDay = lastDayOfLastWeek + 1 Day
4943
- firstDay = new Date(y, 11, lastThursday + 3 + 1);
5001
+ firstDay = new DateTime(y, 11, lastThursday + 3 + 1);
4944
5002
  break;
4945
5003
  case -1:
4946
5004
  // firstDay is the 1st day of the 1st week of the previous year.
4947
5005
  // The first week of the previous year is the week that contains the
4948
5006
  // first Thursday of the previous year.
4949
5007
  let firstThursdayPreviousYear = 1;
4950
- while (new Date(y - 1, 0, firstThursdayPreviousYear).getDay() !== 4) {
5008
+ while (new DateTime(y - 1, 0, firstThursdayPreviousYear).getDay() !== 4) {
4951
5009
  firstThursdayPreviousYear += 1;
4952
5010
  }
4953
- firstDay = new Date(y - 1, 0, firstThursdayPreviousYear - 3);
5011
+ firstDay = new DateTime(y - 1, 0, firstThursdayPreviousYear - 3);
4954
5012
  break;
4955
5013
  }
4956
5014
  const dif = (_date.getTime() - firstDay.getTime()) / 86400000;
@@ -5089,8 +5147,8 @@
5089
5147
  });
5090
5148
  }
5091
5149
  const invertDate = _startDate.getTime() > _endDate.getTime();
5092
- const stopDate = new Date((invertDate ? _startDate : _endDate).getTime());
5093
- let stepDate = new Date((invertDate ? _endDate : _startDate).getTime());
5150
+ const stopDate = DateTime.fromTimestamp((invertDate ? _startDate : _endDate).getTime());
5151
+ let stepDate = DateTime.fromTimestamp((invertDate ? _endDate : _startDate).getTime());
5094
5152
  const timeStopDate = stopDate.getTime();
5095
5153
  let timeStepDate = stepDate.getTime();
5096
5154
  let netWorkingDay = 0;
@@ -5114,8 +5172,7 @@
5114
5172
  returns: ["DATE"],
5115
5173
  returnFormat: { specificFormat: "m/d/yyyy hh:mm:ss" },
5116
5174
  compute: function () {
5117
- let today = new Date();
5118
- today.setMilliseconds(0);
5175
+ let today = DateTime.now();
5119
5176
  const delta = today.getTime() - INITIAL_1900_DAY.getTime();
5120
5177
  const time = today.getHours() / 24 + today.getMinutes() / 1440 + today.getSeconds() / 86400;
5121
5178
  return Math.floor(delta / 86400000) + time;
@@ -5189,8 +5246,8 @@
5189
5246
  returns: ["DATE"],
5190
5247
  returnFormat: { specificFormat: "m/d/yyyy" },
5191
5248
  compute: function () {
5192
- const today = new Date();
5193
- const jsDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
5249
+ const today = DateTime.now();
5250
+ const jsDate = new DateTime(today.getFullYear(), today.getMonth(), today.getDate());
5194
5251
  const delta = jsDate.getTime() - INITIAL_1900_DAY.getTime();
5195
5252
  return Math.round(delta / 86400000);
5196
5253
  },
@@ -5246,10 +5303,10 @@
5246
5303
  }
5247
5304
  const y = _date.getFullYear();
5248
5305
  let dayStart = 1;
5249
- let startDayOfFirstWeek = new Date(y, 0, dayStart);
5306
+ let startDayOfFirstWeek = new DateTime(y, 0, dayStart);
5250
5307
  while (startDayOfFirstWeek.getDay() !== startDayOfWeek) {
5251
5308
  dayStart += 1;
5252
- startDayOfFirstWeek = new Date(y, 0, dayStart);
5309
+ startDayOfFirstWeek = new DateTime(y, 0, dayStart);
5253
5310
  }
5254
5311
  const dif = (_date.getTime() - startDayOfFirstWeek.getTime()) / 86400000;
5255
5312
  if (dif < 0) {
@@ -5303,7 +5360,7 @@
5303
5360
  timesHoliday.add(holiday.getTime());
5304
5361
  });
5305
5362
  }
5306
- let stepDate = new Date(_startDate.getTime());
5363
+ let stepDate = DateTime.fromTimestamp(_startDate.getTime());
5307
5364
  let timeStepDate = stepDate.getTime();
5308
5365
  const unitDay = Math.sign(_numDays);
5309
5366
  let stepDay = Math.abs(_numDays);
@@ -31382,9 +31439,9 @@
31382
31439
  Object.defineProperty(exports, '__esModule', { value: true });
31383
31440
 
31384
31441
 
31385
- __info__.version = '15.2.13';
31386
- __info__.date = '2023-11-24T13:06:49.659Z';
31387
- __info__.hash = 'ea82269';
31442
+ __info__.version = '15.2.14';
31443
+ __info__.date = '2024-01-12T13:37:05.872Z';
31444
+ __info__.hash = '6515f7c';
31388
31445
 
31389
31446
 
31390
31447
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);