Skip to content

DateComponent

javarome edited this page Feb 4, 2025 · 3 revisions

A date component is a value with a unit (year, month, etc.), which allows only valid values.

classDiagram
    class DateComponent {
        value: number
    }
    DateComponent --> Unit: unit
Loading

Each specialization of DateComponent:

  • can parse a different format
  • is validated by a specific validator.
classDiagram
    class DateComponent {
    }
    class Year {
        fromString(str)$: Year
    }
    DateComponent <|-- Year
    class Month {
        fromString(str)$: Month
    }
    DateComponent <|-- Month
    class Day {
        fromString(str)$: Day
    }
    DateComponent <|-- Day
    class Hour {
        fromString(str)$: Hour
    }
    DateComponent <|-- Hour
    class Minute {
        fromString(str)$: Minute
    }
    DateComponent <|-- Minute
    class Second {
        fromString(str)$: Second
    }
    DateComponent <|-- Second
Loading

Parsing

Each date calendar (year, month, day) and time (hour, minute, second) component can also be individually instantiated.

import { Level2Year as EdtfYear } from "@rr0/time/level2/year/index.mjs"

const inTheFifities = EdtfYear.fromString("195X")

Programmatic API

Each date calendar and time component can be individually instantiated.

import { Level2Year as EdtfYear } from "@rr0/time/level2/year/index.mjs"

const someYear = new EdtfYear(1985)
someYear.value  // "1985"
const currentYear = EdtfYear.newInstance()
someYear.value  // Displays current year
Clone this wiki locally