Skip to content

Commit

Permalink
fix: ParsingComponent.get() to return undefined instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
wanasit committed Jul 18, 2020
1 parent a1757f3 commit e1a3c04
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ParsedResult {

export interface ParsedComponents {
readonly isCertain: (c: Component) => boolean;
readonly get: (c: Component) => number | undefined;
readonly get: (c: Component) => number | null;
readonly date: () => Date;
}

Expand Down
4 changes: 2 additions & 2 deletions src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ParsingComponents implements ParsedComponents {
return this.impliedValues[component];
}

return null;
return undefined;
}

date(): Date {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ParsingComponents implements ParsedComponents {
// Javascript Date Object return minus timezone offset
const currentTimezoneOffset = result.utcOffset();
const targetTimezoneOffset =
this.get("timezoneOffset") !== null ? this.get("timezoneOffset") : currentTimezoneOffset;
this.get("timezoneOffset") !== undefined ? this.get("timezoneOffset") : currentTimezoneOffset;

const adjustTimezoneOffset = targetTimezoneOffset - currentTimezoneOffset;
result = result.add(-adjustTimezoneOffset, "minute");
Expand Down
2 changes: 1 addition & 1 deletion test/result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test("Test - Create & manipulate date results", () => {
expect(components.date()).toBeDefined();

// undefined
expect(components.get("weekday")).toBeNull();
expect(components.get("weekday")).toBeUndefined();
expect(components.isCertain("weekday")).toBe(false);

// "imply"
Expand Down

0 comments on commit e1a3c04

Please sign in to comment.