Skip to content

Commit

Permalink
Merge pull request #36 from distributed-lab/fix/dayjs-timestamp
Browse files Browse the repository at this point in the history
Fix/Timestamp converting
  • Loading branch information
napalmpapalam authored Jul 17, 2023
2 parents f35db08 + ccc10f8 commit a4e4a41
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.0.0-rc.2] - 2023-07-17
### Fixed
- `@distributedlab/tools` - `Time` `TimeDate` data when the value is in timestamp format

## [1.0.0-rc.1] - 2023-07-17
### Fixed
- `@distributedlab/tools` - `BN` `toDecimals` method when decimals value equals to this decimals value
Expand Down Expand Up @@ -300,7 +304,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[old repo]: https://github.com/distributed-lab/web-kit-old

[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.1...HEAD
[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.2...HEAD
[1.0.0-rc.2]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.1...1.0.0-rc.2
[1.0.0-rc.1]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.0...1.0.0-rc.1
[1.0.0-rc.0]: https://github.com/distributed-lab/web-kit/compare/0.2.0...1.0.0-rc.0
[0.2.0]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.25...0.2.0
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/fetcher",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "Fetch API wrapper with the extended functionality and simple interface",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jac/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/jac",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "A library for constructing JSON-API compliant requests and responses",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/reactivity",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "Implementation of the reactivity connections to propagate changes between objects",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/tools",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "Collection of common utility functions and classes",
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions packages/tools/src/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ describe('Performs time class unit test', () => {
time.utc(true)
expect(time.ms).toStrictEqual(1677801600000)
})

test('test timestamp, should return correct value', () => {
const time1 = new Time('2023-03-03')
const time2 = new Time(time1.timestamp)
expect(time1.ISO).toEqual(time2.ISO)
})
})
28 changes: 15 additions & 13 deletions packages/tools/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class Time {
}

private _dayjs(date?: TimeDate, format?: TimeFormat): Dayjs {
return dayjs(unwrap(date), format)
return dayjs(parseDate(date), format)
}

private _tz(date: TimeDate, timezone?: string) {
return dayjs.tz(unwrap(date), timezone)
return dayjs.tz(parseDate(date), timezone)
}

public get dayjs(): Dayjs {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Time {
}

public toCalendar(referenceTime?: TimeDate, calendar?: TimeCalendar): string {
return this.#date.calendar(unwrap(referenceTime), calendar)
return this.#date.calendar(parseDate(referenceTime), calendar)
}

public subtract(value: number, unit?: TimeManipulate): Time {
Expand All @@ -153,23 +153,23 @@ export class Time {
}

public isSame(comparisonDate?: TimeDate, unit?: TimeOpUnit): boolean {
return this.#date.isSame(unwrap(comparisonDate), unit)
return this.#date.isSame(parseDate(comparisonDate), unit)
}

public isBefore(comparisonDate?: TimeDate): boolean {
return this.#date.isBefore(unwrap(comparisonDate))
return this.#date.isBefore(parseDate(comparisonDate))
}

public isAfter(comparisonDate?: TimeDate): boolean {
return this.#date.isAfter(unwrap(comparisonDate))
return this.#date.isAfter(parseDate(comparisonDate))
}

public isSameOrAfter(comparisonDate?: TimeDate): boolean {
return this.#date.isSameOrAfter(unwrap(comparisonDate))
return this.#date.isSameOrAfter(parseDate(comparisonDate))
}

public isSameOrBefore(comparisonDate?: TimeDate): boolean {
return this.#date.isSameOrBefore(unwrap(comparisonDate))
return this.#date.isSameOrBefore(parseDate(comparisonDate))
}

public isBetween(
Expand All @@ -179,8 +179,8 @@ export class Time {
inclusivity?: Inclusivity,
): boolean {
return this.#date.isBetween(
unwrap(startDate),
unwrap(endDate),
parseDate(startDate),
parseDate(endDate),
unit,
inclusivity,
)
Expand All @@ -195,23 +195,25 @@ export class Time {
}

public getFrom(date: TimeDate): string {
return this.#date.from(unwrap(date))
return this.#date.from(parseDate(date))
}

public get fromNow(): string {
return this.#date.fromNow()
}

public getTo(date: TimeDate): string {
return this.#date.to(unwrap(date))
return this.#date.to(parseDate(date))
}

public get toNow(): string {
return this.#date.toNow()
}
}

const unwrap = (date: TimeDate): Exclude<TimeDate, Time> => {
const parseDate = (date: TimeDate): Exclude<TimeDate, Time> => {
if (typeof date === 'number') return date * 1000

return date instanceof Time ? date.dayjs : date
}

Expand Down
2 changes: 1 addition & 1 deletion packages/w3p/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/w3p",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"description": "Wrapper for Web3 Providers",
"repository": {
"type": "git",
Expand Down

0 comments on commit a4e4a41

Please sign in to comment.