CKN Technology Core · Date/Time Utility

CKN Technology Core
Date/Time Extensions

This page documents all extended Date.prototype helpers provided by @ckn-technology/core, including formatting, calendar arithmetic, period boundaries, and comparison utilities for business logic such as SLAs, cut-off times, and reporting windows.

Import

To load and enable the custom Date extensions described on this page, import the core package once at the entry point of your application (or any module that runs during startup).

import "@ckn-technology/core";

Once imported, all Date/Time utilities become available on Date.prototype globally in your runtime.

Basic Components & Clone

1. Basic Components

date()

Description
Returns the day of the month as a 2-digit string ("01""31").

Signature

date(): string

Example

new Date("2025-01-07").date(); 
// "07"

month()

Description
Returns the month as a 2-digit string ("01""12").

Signature

month(): string

Example

new Date("2025-03-05").month(); 
// "03"

year()

Returns the full 4-digit year as a number.

year(): number
new Date("2025-03-05").year(); 
// 2025

hours()

Returns hour (0–23) from the current date instance.

hours(): number
new Date("2025-03-05T13:45").hours(); 
// 13

minutes() / seconds()

Returns minutes (0–59) or seconds (0–59) from the instance.

minutes(): number
seconds(): number
new Date("2025-03-05T13:45:30").minutes(); 
// 45
new Date("2025-03-05T13:45:30").seconds(); 
// 30

2. Clone

clone()

Description
Creates a new Date instance with the same timestamp as the current one. Useful for non-mutating operations.

Signature

clone(): Date

Example

const d = new Date();
const c = d.clone();
// d and c share the same time value, but are different instances.

Formats & Helper Methods

3. Basic Formats

dataFormat()

Description
Legacy alias of dateDataFormat(). Returns the date in YYYY-MM-DD format.

Signature

dataFormat(): string

Example

new Date("2025-03-05").dataFormat(); 
// "2025-03-05"

dateDataFormat()

Returns a pure date string YYYY-MM-DD.

dateDataFormat(): string
new Date("2025-03-05").dateDataFormat(); 
// "2025-03-05"

timeDataFormat()

Returns a time string in HH:MM:SS 24-hour format.

timeDataFormat(): string
new Date("2025-03-05T13:45:30").timeDataFormat(); 
// "13:45:30"

dateTimeDataFormat()

Returns combined date and time as YYYY-MM-DD HH:MM:SS.

dateTimeDataFormat(): string
new Date("2025-03-05T13:45:30").dateTimeDataFormat(); 
// "2025-03-05 13:45:30"

4. Custom Formatter

format(formatString)

Description
Returns a formatted string using tokens like {dddd}, {dd}, {MMM}, {yyyy}, {HH}, {mm}, {ss}:

  • {dddd} · weekday long (e.g. Wednesday)
  • {ddd} · weekday short (e.g. Wed)
  • {MMMM} · month long (e.g. March)
  • {MMM} · month short (e.g. Mar)
  • {yyyy} / {yy} · year
  • {MM} · 2-digit month, {dd} · 2-digit day
  • {HH} · hours, {mm} · minutes, {ss} · seconds

Signature

format(formatString: string): string

Example

new Date("2025-03-05T13:45")
  .format("{dddd}, {dd} {MMM} {yyyy} {HH}:{mm}");
// "Wednesday, 05 Mar 2025 13:45"

5. Adders

All adders return a new Date instance (do not mutate this), making them safe for fluent chains.

addDays(days, day?)

Adds a number of days. Optional day overrides the base date; otherwise uses the current instance.

Signature

addDays(days: number, day?: Date): Date

Example

new Date("2025-03-01").addDays(5);
// 2025-03-06

addHours(h, day?)

Adds hours; handles day rollover automatically.

addHours(h: number, day?: Date): Date
new Date("2025-03-05T10:00").addHours(3);
// 2025-03-05T13:00

addMinutes(m, day?)

Adds minutes, carrying over to hours/days.

addMinutes(m: number, day?: Date): Date
new Date("2025-03-05T10:00").addMinutes(90);
// 2025-03-05T11:30

addSeconds(s, day?)

Adds seconds, carrying over to minutes/hours.

addSeconds(s: number, day?: Date): Date
new Date("2025-03-05T10:00:00").addSeconds(30);
// 2025-03-05T10:00:30

addMilliseconds(ms, day?)

Adds milliseconds for fine-grained timing.

addMilliseconds(ms: number, day?: Date): Date
new Date("2025-03-05T10:00:00").addMilliseconds(500);
// 10:00:00.500

addMonths(months, day?)

Adds calendar months, adjusting overflow (e.g. 31st → last day of month).

addMonths(months: number, day?: Date): Date
new Date("2025-01-31").addMonths(1);
// 2025-02-28 (or 29 in a leap year)

addYears(years, day?)

Adds calendar years, respecting leap years where possible.

addYears(years: number, day?: Date): Date
new Date("2025-03-01").addYears(2);
// 2027-03-01

addWeeks(weeks, day?)

Adds whole weeks (weeks × 7 days). Great for recurring schedules.

addWeeks(weeks: number, day?: Date): Date
new Date("2025-03-01").addWeeks(2);
// 2025-03-15

6. Diff Helpers

Compute differences between this date and another Date instance.

diffMillis(other)

Raw difference in milliseconds (this - other).

diffMillis(other: Date): number

diffSeconds(other)

Difference in seconds (millis / 1000).

diffSeconds(other: Date): number

diffMinutes(other)

Difference in minutes (millis / (1000*60)).

diffMinutes(other: Date): number

diffHours(other)

Difference in hours (millis / (1000*60*60)).

diffHours(other: Date): number

diffDays(other)

Difference in whole days, ignoring time portion. Ideal for SLAs or due-date logic.

Signature

diffDays(other: Date): number

Example

new Date("2025-03-10").diffDays(new Date("2025-03-05"));
// 5

7. Start / End of Period

startOfDay()

Returns a new date at 00:00:00.000 of the same day.

startOfDay(): Date

endOfDay()

Returns a new date at 23:59:59.999 of the same day.

endOfDay(): Date

startOfMonth()

Returns first day of the month at midnight.

startOfMonth(): Date

endOfMonth()

Returns last moment of the month (last day, 23:59:59.999).

endOfMonth(): Date

startOfWeek(firstDayOfWeek = 1)

Returns the start of the week. Default firstDayOfWeek = 1 (Monday), or use 0 for Sunday.

startOfWeek(firstDayOfWeek?: number): Date

endOfWeek(firstDayOfWeek = 1)

Returns startOfWeek + 7 days - 1 ms, representing the week’s end.

endOfWeek(firstDayOfWeek?: number): Date

8. ISO Helpers

toISODate()

Returns YYYY-MM-DD (ISO-like date).

toISODate(): string

toISOTime()

Returns HH:MM:SS (24-hour time).

toISOTime(): string

toISODateTime()

Returns YYYY-MM-DD HH:MM:SS, convenient for logs and DB rows.

toISODateTime(): string

9. Text Helpers

weekdayShort()

Returns "Sun""Sat".

weekdayShort(): string

weekdayLong()

Returns full weekday "Sunday""Saturday".

weekdayLong(): string

monthShort()

Returns "Jan""Dec".

monthShort(): string

monthLong()

Returns "January""December".

monthLong(): string

10. Checks & Queries

isLeapYear()

Returns true if the year of this date is a leap year.

isLeapYear(): boolean

daysInMonth()

Returns number of days in the month (28–31).

daysInMonth(): number

isWeekend()

Returns true if Saturday or Sunday.

isWeekend(): boolean

isWeekday()

Returns true if not weekend.

isWeekday(): boolean

isSameDay(other)

Returns true if year/month/day are equal (time ignored).

isSameDay(other: Date): boolean

isBetween(start, end)

Inclusive check if this timestamp lies between start and end.

isBetween(start: Date, end: Date): boolean

quarter()

Returns the quarter of the year (14) based on month. Useful for financial and reporting logic.

Signature

quarter(): number

Example

new Date("2025-05-01").quarter(); 
// 2