Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/time date typo #31

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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