@sprucelabs/calendar-utils 42.0.600 → 42.0.601

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.
@@ -16,7 +16,7 @@ export default class DateParser {
16
16
  parse(str) {
17
17
  const now = this.now();
18
18
  const date = dateUtil.splitDate(now);
19
- let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: ]/g, '');
19
+ let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: \/]/g, '');
20
20
  const original = parsed;
21
21
  const context = {
22
22
  hasYear: false,
@@ -32,7 +32,7 @@ export default class DateParser {
32
32
  if (parsed === original) {
33
33
  return null;
34
34
  }
35
- let normalized = dateUtil.date({
35
+ const normalized = dateUtil.date({
36
36
  ...date,
37
37
  milliseconds: 0,
38
38
  second: 0,
@@ -2,11 +2,11 @@ import { Locale } from '../types/calendar.types';
2
2
  import { Parser } from './AbstractParser';
3
3
  export default class ParserFactory {
4
4
  private locale;
5
- all(): Parser[];
6
5
  private now;
7
6
  private strategies;
8
7
  private constructor();
8
+ all(): Parser[];
9
9
  static Factory(now: () => number, locale: Locale): ParserFactory;
10
10
  Parser(parserType: ParserStrategy): Parser;
11
11
  }
12
- export type ParserStrategy = 'Year' | 'Month' | 'Dow' | 'Time' | 'Week';
12
+ export type ParserStrategy = 'Year' | 'Month' | 'Dow' | 'Time' | 'Week' | 'UsDate';
@@ -1,18 +1,10 @@
1
1
  import DowParser from './strategies/DowParser.js';
2
2
  import MonthParser from './strategies/MonthParser.js';
3
3
  import TimeParser from './strategies/TimeParser.js';
4
+ import UsDateParser from './strategies/UsDateParser.js';
4
5
  import WeekParser from './strategies/WeekParser.js';
5
6
  import YearParser from './strategies/YearParser.js';
6
7
  export default class ParserFactory {
7
- all() {
8
- return [
9
- this.Parser('Year'),
10
- this.Parser('Month'),
11
- this.Parser('Dow'),
12
- this.Parser('Week'),
13
- this.Parser('Time'),
14
- ];
15
- }
16
8
  constructor(now, locale) {
17
9
  this.strategies = {
18
10
  Year: () => new YearParser(this.now, this.locale),
@@ -20,10 +12,21 @@ export default class ParserFactory {
20
12
  Dow: () => new DowParser(this.now, this.locale),
21
13
  Time: () => new TimeParser(this.now, this.locale),
22
14
  Week: () => new WeekParser(this.now, this.locale),
15
+ UsDate: () => new UsDateParser(this.now, this.locale),
23
16
  };
24
17
  this.now = now;
25
18
  this.locale = locale;
26
19
  }
20
+ all() {
21
+ return [
22
+ this.Parser('UsDate'),
23
+ this.Parser('Year'),
24
+ this.Parser('Month'),
25
+ this.Parser('Dow'),
26
+ this.Parser('Week'),
27
+ this.Parser('Time'),
28
+ ];
29
+ }
27
30
  static Factory(now, locale) {
28
31
  return new this(now, locale);
29
32
  }
@@ -0,0 +1,4 @@
1
+ import { AbstractParser, ParserContext, SplitDate } from '../AbstractParser';
2
+ export default class UsDateParser extends AbstractParser {
3
+ parse(str: string, date: SplitDate, context: ParserContext): string;
4
+ }
@@ -0,0 +1,18 @@
1
+ import { AbstractParser } from '../AbstractParser.js';
2
+ export default class UsDateParser extends AbstractParser {
3
+ parse(str, date, context) {
4
+ const matches = str.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/);
5
+ if (matches) {
6
+ date.month = parseInt(matches[1]) - 1;
7
+ date.day = parseInt(matches[2]);
8
+ date.year = parseInt(matches[3].length === 2 ? `20${matches[3]}` : matches[3]);
9
+ date.hour = -this.locale.getTimezoneOffsetMinutes() / 60;
10
+ date.minute = 0;
11
+ date.second = 0;
12
+ date.milliseconds = 0;
13
+ str = str.replace(matches[0], '');
14
+ context.hasYear = true;
15
+ }
16
+ return str;
17
+ }
18
+ }
@@ -21,7 +21,7 @@ class DateParser {
21
21
  parse(str) {
22
22
  const now = this.now();
23
23
  const date = date_utility_1.default.splitDate(now);
24
- let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: ]/g, '');
24
+ let parsed = str.toLocaleLowerCase().replace(/[^a-z0-9: \/]/g, '');
25
25
  const original = parsed;
26
26
  const context = {
27
27
  hasYear: false,
@@ -37,7 +37,7 @@ class DateParser {
37
37
  if (parsed === original) {
38
38
  return null;
39
39
  }
40
- let normalized = date_utility_1.default.date({
40
+ const normalized = date_utility_1.default.date({
41
41
  ...date,
42
42
  milliseconds: 0,
43
43
  second: 0,
@@ -2,11 +2,11 @@ import { Locale } from '../types/calendar.types';
2
2
  import { Parser } from './AbstractParser';
3
3
  export default class ParserFactory {
4
4
  private locale;
5
- all(): Parser[];
6
5
  private now;
7
6
  private strategies;
8
7
  private constructor();
8
+ all(): Parser[];
9
9
  static Factory(now: () => number, locale: Locale): ParserFactory;
10
10
  Parser(parserType: ParserStrategy): Parser;
11
11
  }
12
- export type ParserStrategy = 'Year' | 'Month' | 'Dow' | 'Time' | 'Week';
12
+ export type ParserStrategy = 'Year' | 'Month' | 'Dow' | 'Time' | 'Week' | 'UsDate';
@@ -6,18 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const DowParser_1 = __importDefault(require("./strategies/DowParser"));
7
7
  const MonthParser_1 = __importDefault(require("./strategies/MonthParser"));
8
8
  const TimeParser_1 = __importDefault(require("./strategies/TimeParser"));
9
+ const UsDateParser_1 = __importDefault(require("./strategies/UsDateParser"));
9
10
  const WeekParser_1 = __importDefault(require("./strategies/WeekParser"));
10
11
  const YearParser_1 = __importDefault(require("./strategies/YearParser"));
11
12
  class ParserFactory {
12
- all() {
13
- return [
14
- this.Parser('Year'),
15
- this.Parser('Month'),
16
- this.Parser('Dow'),
17
- this.Parser('Week'),
18
- this.Parser('Time'),
19
- ];
20
- }
21
13
  constructor(now, locale) {
22
14
  this.strategies = {
23
15
  Year: () => new YearParser_1.default(this.now, this.locale),
@@ -25,10 +17,21 @@ class ParserFactory {
25
17
  Dow: () => new DowParser_1.default(this.now, this.locale),
26
18
  Time: () => new TimeParser_1.default(this.now, this.locale),
27
19
  Week: () => new WeekParser_1.default(this.now, this.locale),
20
+ UsDate: () => new UsDateParser_1.default(this.now, this.locale),
28
21
  };
29
22
  this.now = now;
30
23
  this.locale = locale;
31
24
  }
25
+ all() {
26
+ return [
27
+ this.Parser('UsDate'),
28
+ this.Parser('Year'),
29
+ this.Parser('Month'),
30
+ this.Parser('Dow'),
31
+ this.Parser('Week'),
32
+ this.Parser('Time'),
33
+ ];
34
+ }
32
35
  static Factory(now, locale) {
33
36
  return new this(now, locale);
34
37
  }
@@ -0,0 +1,4 @@
1
+ import { AbstractParser, ParserContext, SplitDate } from '../AbstractParser';
2
+ export default class UsDateParser extends AbstractParser {
3
+ parse(str: string, date: SplitDate, context: ParserContext): string;
4
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AbstractParser_1 = require("../AbstractParser");
4
+ class UsDateParser extends AbstractParser_1.AbstractParser {
5
+ parse(str, date, context) {
6
+ const matches = str.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/);
7
+ if (matches) {
8
+ date.month = parseInt(matches[1]) - 1;
9
+ date.day = parseInt(matches[2]);
10
+ date.year = parseInt(matches[3].length === 2 ? `20${matches[3]}` : matches[3]);
11
+ date.hour = -this.locale.getTimezoneOffsetMinutes() / 60;
12
+ date.minute = 0;
13
+ date.second = 0;
14
+ date.milliseconds = 0;
15
+ str = str.replace(matches[0], '');
16
+ context.hasYear = true;
17
+ }
18
+ return str;
19
+ }
20
+ }
21
+ exports.default = UsDateParser;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "42.0.600",
6
+ "version": "42.0.601",
7
7
  "files": [
8
8
  "build/**/*",
9
9
  "!build/__tests__",