Skip to content

Commit

Permalink
Merge pull request #31 from distributed-lab/fix/time-date-typo
Browse files Browse the repository at this point in the history
Fix/time date typo
  • Loading branch information
napalmpapalam authored Jul 5, 2023
2 parents 572fa32 + 5aaecc8 commit 5c3994d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 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]

## [0.2.0-rc.22] - 2023-06-28
### Changed
- `@distributedlab/tools` - Extend `TimeDate` type with `Time` instance to be able to use as argument

## [0.2.0-rc.21] - 2023-06-28
### Fixed
- `@distributedlab/fetcher` - Building URL from base URL and endpoint with query params
Expand Down Expand Up @@ -249,7 +253,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/0.2.0-rc.21...HEAD
[Unreleased]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.22...HEAD
[0.2.0-rc.22]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.21...0.2.0-rc.22
[0.2.0-rc.21]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.20...0.2.0-rc.21
[0.2.0-rc.20]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.19...0.2.0-rc.20
[0.2.0-rc.19]: https://github.com/distributed-lab/web-kit/compare/0.2.0-rc.18...0.2.0-rc.19
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": "0.2.0-rc.21",
"version": "0.2.0-rc.22",
"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": "0.2.0-rc.21",
"version": "0.2.0-rc.22",
"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": "0.2.0-rc.21",
"version": "0.2.0-rc.22",
"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": "0.2.0-rc.21",
"version": "0.2.0-rc.22",
"description": "Collection of common utility functions and classes",
"repository": {
"type": "git",
Expand Down
36 changes: 23 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(date, format)
return dayjs(unwrap(date), format)
}

private _tz(date: TimeDate, timezone?: string) {
return dayjs.tz(date, timezone)
return dayjs.tz(unwrap(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(referenceTime, calendar)
return this.#date.calendar(unwrap(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(comparisonDate, unit)
return this.#date.isSame(unwrap(comparisonDate), unit)
}

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

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

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

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

public isBetween(
Expand All @@ -178,7 +178,12 @@ export class Time {
unit?: TimeManipulate,
inclusivity?: Inclusivity,
): boolean {
return this.#date.isBetween(startDate, endDate, unit, inclusivity)
return this.#date.isBetween(
unwrap(startDate),
unwrap(endDate),
unit,
inclusivity,
)
}

public diff(
Expand All @@ -190,21 +195,26 @@ export class Time {
}

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

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

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

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

export const time = (date?: TimeDate, format?: TimeFormat): Time =>
new Time(date, format)
const unwrap = (date: TimeDate): Exclude<TimeDate, Time> => {
return date instanceof Time ? date.dayjs : date
}

export const time = (date?: TimeDate, format?: TimeFormat): Time => {
return new Time(date, format)
}
4 changes: 3 additions & 1 deletion packages/tools/src/types/time.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Dayjs } from 'dayjs'

import type { Time } from '@/time'

export type IsoDate = string // RFC3339Nano ISO Date String

export type UnixDate = number // Unix time

export type Inclusivity = '()' | '[)' | '(]' | '[]' // Inclusivity

export type TimeDate = string | number | Date | Dayjs | null | undefined
export type TimeDate = Time | Date | Dayjs | string | number | null | undefined

export type TimeFormat =
| {
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": "0.2.0-rc.21",
"version": "0.2.0-rc.22",
"description": "Wrapper for Web3 Providers",
"repository": {
"type": "git",
Expand Down

0 comments on commit 5c3994d

Please sign in to comment.