Skip to main content
This release is 1 version behind 0.9.3 — the latest version of @dnl-fm/zeit-ts. Jump to latest

Built and signed on GitHub Actions

Helps syncing/reading user dates in your database

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.9.2)
class UserZeit

Represents a Zeit (time) object in the user's timezone.

Constructors

new
UserZeit(
dateTime: DateTime,
now?: DateTime,
)

Creates a new UserZeit instance.

Methods

private
buildCycle(
interval: ZeitInterval,
iteration: number,
now?: UserZeit,
): UserZeit

Builds a cycle DateTime object.

private
buildPeriod(
startsAt: UserZeit,
endsAt: UserZeit,
): ZeitPeriod

Builds a ZeitPeriod object from start and end dates.

Clones the UserZeit instance.

Gets the current cycle based on the current date.

private
cycleEndsAt(
interval: ZeitInterval,
iteration: number,
startsAt?: UserZeit,
): UserZeit

Generates a cycle end date.

private
cycleStartsAt(
interval: ZeitInterval,
iteration: number,
now?: UserZeit,
): UserZeit

Generates a cycle start date.

cycles(
numberOfCycles: number,
options?: { interval: ZeitInterval; startZeit?: UserZeit; },
): Cycles

Generates cycles starting from this UserZeit.

cyclesFrom(
startZeit: UserZeit,
numberOfCycles: number,
options?: { interval: ZeitInterval; },
): Cycles

Generates cycles starting from a specified date.

cyclesUntil(
endZeit: UserZeit,
options?: { interval: ZeitInterval; },
): Cycles

Generates cycles starting from this UserZeit until a specified end date.

Calculates the number of days between this UserZeit and another UserZeit.

endOf(unit: DateTimeUnit): UserZeit

Sets the DateTime to the end of the specified unit.

Formats the date/time using the specified format.

get(unit: keyof DateTime): number

Gets the value of the specified unit from the DateTime object.

private
getNearestCycleStart(
startZeit: UserZeit,
interval: ZeitInterval,
): UserZeit

Gets the nearest cycle start date.

private
getNow(): UserZeit

Gets the current DateTime, either from the stored 'now' value or creates a new one.

Gets the timezone of this UserZeit.

getZeit(): DateTime

Gets the Luxon DateTime object for this UserZeit.

Checks if this UserZeit is after another UserZeit.

Checks if this UserZeit is before another UserZeit.

Checks if this UserZeit has a different date than another UserZeit.

Checks if this UserZeit has the same date as another UserZeit.

Checks if this UserZeit is after or the same as another UserZeit.

Checks if this UserZeit is before or the same as another UserZeit.

Checks if this UserZeit is after or the same as another UserZeit.

Checks if this UserZeit is before or the same as another UserZeit.

Checks if the DateTime is valid.

minus(duration: DurationLike): UserZeit

Subtracts a duration from the current time.

Gets the next cycle based on the current date.

plus(duration: DurationLike): UserZeit

Adds a duration to the current time.

Gets the previous cycle based on the current date.

set(values: DateObjectUnits): UserZeit

Sets specified components of the date/time.

Sets the time to midnight.

startOf(unit: DateTimeUnit): UserZeit

Sets the DateTime to the start of the specified unit.

Converts this UserZeit to a DatabaseZeit in UTC.

Converts the UserZeit to a DatabaseZeit ISO 8601 string.

Converts the UserZeit to a DatabaseZeit ISO 8601 date string (without time).

Converts the UserZeit to an ISO 8601 string.

Converts the UserZeit to an ISO 8601 date string (without time).

Static Methods

fromNow(
timezone: Timezone,
now?: DateTime,
): UserZeit

Creates a UserZeit instance representing the current time in the specified timezone.

sortObjects<T extends { [key: string]: unknown; }>(
items: T[],
key: keyof T & string,
direction?: "asc" | "desc",
): T[]

Sorts an array of objects containing UserZeit properties.

Add Package

deno add jsr:@dnl-fm/zeit-ts

Import symbol

import { UserZeit } from "@dnl-fm/zeit-ts";

---- OR ----

Import directly with a jsr specifier

import { UserZeit } from "jsr:@dnl-fm/zeit-ts";

Add Package

npx jsr add @dnl-fm/zeit-ts

Import symbol

import { UserZeit } from "@dnl-fm/zeit-ts";

Add Package

yarn dlx jsr add @dnl-fm/zeit-ts

Import symbol

import { UserZeit } from "@dnl-fm/zeit-ts";

Add Package

pnpm dlx jsr add @dnl-fm/zeit-ts

Import symbol

import { UserZeit } from "@dnl-fm/zeit-ts";

Add Package

bunx jsr add @dnl-fm/zeit-ts

Import symbol

import { UserZeit } from "@dnl-fm/zeit-ts";