-
Notifications
You must be signed in to change notification settings - Fork 0
DateComponent
javarome edited this page Feb 20, 2025
·
4 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
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
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")
Some digits can be left unspecified using the X
character, leading to:
-
year precision:
-
Level1Date.fromString(‘201X’)
will return a date whose year component is an interval between 2010 and 2019 -
Level1Date.fromString(‘20XX’)
will return a date whose year component is an interval between 2000 and 2099
-
-
month precision:
-
Level1Date.fromString(‘2004-XX’)
will return a date whose month component is an interval between 01 and 12
-
-
dat precision:
-
Level1Date.fromString(‘1985-04-XX’)
will return a date whose day component is an interval between 01 and 31 -
Level1Date.fromString(‘1985-XX-XX’)
will return a date whose month component is an interval between 01 and 12 and day component is an interval between 01 and 31
-
Dates components can be serialized as specifications. For instance:
year = Level2Year.fromString("1985")
json = JSON.stringify(year)
spec = JSON.parse(json)
sameYear = new Level2Year(spec)
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