Skip to content
javarome edited this page Nov 1, 2024 · 2 revisions

A date is an aggregation of (optional) date components:

classDiagram
    class Year {
    }
    class Month {
    }
    class Day {
    }
    class Hour {
    }
    class Minute {
    }
    class Second {
    }
    class Date {
        getTime(): number
        compare(otherDate): number
        isEqual(otherDate): boolean
        isBefore(otherDate): boolean
        isAfter(otherDate): boolean
        delta(otherDate): Level0Duration
        toString(): string
        fromString(str)$: Level0Date
        newInstance()$: Level0Date
    }
    Date --> Year: year?
    Date --> Month: month?
    Date --> Day: day?
    Date --> Hour: hour?
    Date --> Minute: minute?
    Date --> Second: second?
Loading

Parsing

import { Level2Date as EdtfDate } from "@rr0/time"

const maybeAugust = EdtfDate.fromString("2024-?08-25")
maybeAugust.month.value // 8
maybeAugust.month.uncertain // true
maybeAugust.year.uncertain // false
maybeAugust.uncertain // true
const aroundMarch2025 = EdtfDate.fromString("2025-03~")
aroundMarch2025.approximate = true

Programmatic API

You can select the API level you want to use. For example using level 0:

import { Level2Date as EdtfDate } from "@rr0/time/level2/date/index.mjs"

const currentDate = EdtfDate.newInstance()
const someDate = new EdtfDate({ year: 1985, month: 4, day: 12 })

Several APIs are available on dates, such as:

maybeAugust.isEqual(aroundMarch2025)  // false
maybeAugust.isBefore(aroundMarch2025) // true
aroundMarch2025.isAfter(maybeAugust)  // true
const delta = aroundMarch2025.delta(maybeAugust).toSpec()
delta.months //  6
delta.days   // 16
Clone this wiki locally