Skip to content

Commit

Permalink
feat(datetime): introduce utc and local shorthands (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsndr authored May 21, 2024
1 parent cda2986 commit 29d46cb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ export class DateTime implements DateTimeLike {
return new DateTime(numeric);
}

/**
* This method is shorthand for `DateTime.create` with `utc` set to `false`.
*/
public static local(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
): DateTime {
return DateTime.create(year, month, day, hour, minute, second, false);
}

/**
* This method is shorthand for `DateTime.create` with `utc` set to `true`.
*/
public static utc(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
): DateTime {
return DateTime.create(year, month, day, hour, minute, second, true);
}

/**
* Creates a new DateTime object from the given plain object.
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ describe(DateTime, () => {
});
});

describe('utc', () => {
test('should create utc object from', () => {
const datetime = DateTime.utc(2005, 9, 4, 9, 1, 2);

expect(datetime.utc).toBeTruthy();
});
});

describe('local', () => {
test('should create local object from', () => {
const datetime = DateTime.local(2005, 9, 4, 9, 1, 2);

expect(datetime.utc).toBeFalsy();
});
});

describe('fromObject', () => {
test.each([
{
Expand Down

0 comments on commit 29d46cb

Please sign in to comment.