@arsedizioni/ars-utils 22.0.31 → 22.0.33

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.
@@ -168,22 +168,20 @@ class DateFnsAdapter extends DateAdapter {
168
168
  if (date < 1) {
169
169
  throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
170
170
  }
171
- // Passing the year to the constructor causes year numbers <100 to be converted to 19xx.
172
- // To work around this we use `setFullYear` and `setHours` instead.
173
- const result = new Date();
174
- result.setFullYear(year, month, date);
175
- result.setHours(0, 0, 0, 0);
176
- const result2 = new TZDate(result, 'Europe/Rome');
177
- if (result2.getMonth() !== month) {
171
+ if (month < 0 || month > 11) {
172
+ throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
173
+ }
174
+ const result = new TZDate(year, month, date, 0, 0, 0, 0, 'Europe/Rome');
175
+ if (result.getMonth() !== month) {
178
176
  throw Error(`Invalid date "${date}" for month with index "${month}".`);
179
177
  }
180
- return result2;
178
+ return result;
181
179
  }
182
180
  /**
183
181
  * Returns today's date in the local timezone.
184
182
  */
185
183
  today() {
186
- return new Date();
184
+ return new TZDate(new Date(), 'Europe/Rome');
187
185
  }
188
186
  /**
189
187
  * Parses a value into a `Date`.
@@ -205,7 +203,9 @@ class DateFnsAdapter extends DateAdapter {
205
203
  throw Error('Formats array must not be empty.');
206
204
  }
207
205
  for (const currentFormat of formats) {
208
- const fromFormat = parse(value, currentFormat, new Date(), { locale: this.locale });
206
+ const fromFormat = parse(value, currentFormat, new TZDate(new Date(), 'Europe/Rome'), {
207
+ locale: this.locale
208
+ });
209
209
  if (this.isValid(fromFormat)) {
210
210
  return new TZDate(fromFormat, 'Europe/Rome');
211
211
  }