@js-joda/core 5.5.2 → 5.6.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-joda/core",
3
- "version": "5.5.2",
3
+ "version": "5.6.0",
4
4
  "description": "a date and time library for javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,5 +48,5 @@
48
48
  "sourceMap": false,
49
49
  "instrument": false
50
50
  },
51
- "gitHead": "8d78c174b570252ae707da314a444e2a9bd1f3fa"
51
+ "gitHead": "e78db48870eddc16cc35f81cee07f99918d7bf8f"
52
52
  }
@@ -174,6 +174,39 @@ export class DateTimeFormatterBuilder {
174
174
  return this;
175
175
  }
176
176
 
177
+ /**
178
+ * Appends a default value for a field to the formatter for use in parsing.
179
+ * <p>
180
+ * This appends an instruction to the builder to inject a default value
181
+ * into the parsed result. This is especially useful in conjunction with
182
+ * optional parts of the formatter.
183
+ * <p>
184
+ * For example, consider a formatter that parses the year, followed by
185
+ * an optional month, with a further optional day-of-month. Using such a
186
+ * formatter would require the calling code to check whether a full date,
187
+ * year-month or just a year had been parsed. This method can be used to
188
+ * default the month and day-of-month to a sensible value, such as the
189
+ * first of the month, allowing the calling code to always get a date.
190
+ * <p>
191
+ * During formatting, this method has no effect.
192
+ * <p>
193
+ * During parsing, the current state of the parse is inspected.
194
+ * If the specified field has no associated value, because it has not been
195
+ * parsed successfully at that point, then the specified value is injected
196
+ * into the parse result. Injection is immediate, thus the field-value pair
197
+ * will be visible to any subsequent elements in the formatter.
198
+ * As such, this method is normally called at the end of the builder.
199
+ *
200
+ * @param {TemporalField} field the field to default the value of, not null
201
+ * @param {number} value the value to default the field to
202
+ * @return {DateTimeFormatterBuilder} this, for chaining, not null
203
+ */
204
+ parseDefaulting(field, value) {
205
+ requireNonNull(field);
206
+ this._appendInternal(new DefaultingParser(field, value));
207
+ return this;
208
+ }
209
+
177
210
  /**
178
211
  * appendValue function overloading
179
212
  */
@@ -1527,6 +1560,44 @@ class InstantPrinterParser {
1527
1560
  }
1528
1561
  }
1529
1562
 
1563
+ /**
1564
+ * Used by parseDefaulting().
1565
+ * @implements {DateTimePrinterParser}
1566
+ * @private
1567
+ */
1568
+ class DefaultingParser {
1569
+ /**
1570
+ * @param {TemporalField} field
1571
+ * @param {number} value
1572
+ */
1573
+ constructor(field, value) {
1574
+ this._field = field;
1575
+ this._value = value;
1576
+ }
1577
+
1578
+ /**
1579
+ * @param {DateTimePrintContext} context
1580
+ * @param {StringBuilder} buf
1581
+ * @return {boolean}
1582
+ */
1583
+ print() {
1584
+ return true;
1585
+ }
1586
+
1587
+
1588
+ /**
1589
+ * @param {DateTimeParseContext} context
1590
+ * @param {string} text
1591
+ * @param {number} position
1592
+ * @returns {number}
1593
+ */
1594
+ parse(context, text, position) {
1595
+ if (context.getParsed(this._field) == null) {
1596
+ context.setParsedField(this._field, this._value, position, position);
1597
+ }
1598
+ return position;
1599
+ }
1600
+ }
1530
1601
 
1531
1602
  export function _init() {
1532
1603
  ReducedPrinterParser.BASE_DATE = LocalDate.of(2000, 1, 1);
@@ -2162,6 +2162,14 @@ export class DateTimeFormatter {
2162
2162
  static ISO_OFFSET_DATE_TIME: DateTimeFormatter;
2163
2163
  static ISO_OFFSET_TIME: DateTimeFormatter;
2164
2164
  static ISO_ZONED_DATE_TIME: DateTimeFormatter;
2165
+ static BASIC_ISO_DATE: DateTimeFormatter;
2166
+ static ISO_OFFSET_DATE: DateTimeFormatter;
2167
+ static ISO_OFFSET_TIME: DateTimeFormatter;
2168
+ static ISO_ORDINAL_DATE: DateTimeFormatter;
2169
+ static ISO_WEEK_DATE: DateTimeFormatter;
2170
+ static ISO_DATE: DateTimeFormatter;
2171
+ static ISO_TIME: DateTimeFormatter;
2172
+ static ISO_DATE_TIME: DateTimeFormatter;
2165
2173
 
2166
2174
  static ofPattern(pattern: string): DateTimeFormatter;
2167
2175
  static parsedExcessDays(): TemporalQuery<Period>;
@@ -2185,7 +2193,7 @@ export class DateTimeFormatterBuilder {
2185
2193
 
2186
2194
  append(formatter: DateTimeFormatter): DateTimeFormatterBuilder;
2187
2195
  appendFraction(field: TemporalField, minWidth: number, maxWidth: number, decimalPoint: boolean): DateTimeFormatterBuilder;
2188
- appendInstant(fractionalDigits: number): DateTimeFormatterBuilder;
2196
+ appendInstant(fractionalDigits?: number): DateTimeFormatterBuilder;
2189
2197
  appendLiteral(literal: any): DateTimeFormatterBuilder;
2190
2198
  appendOffset(pattern: string, noOffsetText: string): DateTimeFormatterBuilder;
2191
2199
  appendOffsetId(): DateTimeFormatterBuilder;
@@ -2198,6 +2206,7 @@ export class DateTimeFormatterBuilder {
2198
2206
  padNext(): DateTimeFormatterBuilder;
2199
2207
  parseCaseInsensitive(): DateTimeFormatterBuilder;
2200
2208
  parseCaseSensitive(): DateTimeFormatterBuilder;
2209
+ parseDefaulting(field: TemporalField, value: number): DateTimeFormatterBuilder;
2201
2210
  parseLenient(): DateTimeFormatterBuilder;
2202
2211
  parseStrict(): DateTimeFormatterBuilder;
2203
2212
  toFormatter(resolverStyle?: ResolverStyle): DateTimeFormatter;
@@ -211,6 +211,7 @@ declare module "js-joda" {
211
211
  padNext(): DateTimeFormatterBuilder;
212
212
  parseCaseInsensitive(): DateTimeFormatterBuilder;
213
213
  parseCaseSensitive(): DateTimeFormatterBuilder;
214
+ parseDefaulting(field: TemporalField, value: number): DateTimeFormatterBuilder;
214
215
  parseLenient(): DateTimeFormatterBuilder;
215
216
  parseStrict(): DateTimeFormatterBuilder;
216
217
  toFormatter(resolverStyle: ResolverStyle): DateTimeFormatter