Chrononuensis supports various tokens that allow parsing date and time components from formatted strings.
By default, a character displayed in the format is interpreted as a format specifier unless it is not part of the list of format specifiers. This allows for intuitive formats such as yyyy-MM
, which are easily readable.
If a character is part of the format specifiers but needs to be treated as a literal, enclose it in either single '
or double quotes "
. For example, in 'year:'yyyy
, the y
in year is interpreted as a literal since it is enclosed in quotes. If your format includes a single quote character, enclose the entire string in double quotes, and vice versa, to avoid ambiguity.
For complex format specifiers, such as Roman numerals, enclose the format specifiers in curly braces and separate different parts using colons (:
).
Examples:
The following formats specify a four-digit year and a two-digit, zero-padded month:
Format |
Simple |
Quoted |
Curly |
Standard numeric representation |
yyyy-MM |
yyyy'-'MM |
{yyyy}'-'{MM} |
Roman numeral for month |
|
|
{yyyy}-{MM:RN} |
Roman numeral for year |
|
|
{yyyy:RN}-{MM} |
List of Tokens
Below is a list of all supported tokens, grouped by category.
Century
Token Name |
Pattern |
Description |
Digit |
c |
Extracts the century component. |
PaddedDigit |
cc |
Extracts the century component. |
RomanNumeral |
c:RN |
Extracts the century component. |
RomanNumeral |
cc:RN |
Extracts the century component. |
Decade
Token Name |
Pattern |
Description |
DigitOn2 |
tt |
Extracts the decade component. |
DigitOn4 |
tttt |
Extracts the decade component. |
Year
Token Name |
Pattern |
Description |
DigitOn2 |
yy |
Extracts the year component. |
DigitOn4 |
yyyy |
Extracts the year component. |
RomanNumeralShort |
yy:RN |
Extracts the year component. |
RomanNumeral |
yyyy:RN |
Extracts the year component. |
Semester
Token Name |
Pattern |
Description |
Digit |
S |
Extracts the semester component. |
Quarter
Token Name |
Pattern |
Description |
Digit |
q |
Extracts the quarter component. |
Month
Token Name |
Pattern |
Description |
Digit |
M |
Extracts the month component. |
PaddedDigit |
MM |
Extracts the month component. |
Abbreviation |
MMM |
Extracts the month component. |
Label |
MMMM |
Extracts the month component. |
RomanNumeral |
M:RN |
Extracts the month component. |
RomanNumeral |
MM:RN |
Extracts the month component. |
Week
Token Name |
Pattern |
Description |
Digit |
w |
Extracts the week component. |
PaddedDigit |
ww |
Extracts the week component. |
DayOfYear
Token Name |
Pattern |
Description |
Digit |
j |
Extracts the dayofyear component. |
PaddedDigit |
jjj |
Extracts the dayofyear component. |
Day
Token Name |
Pattern |
Description |
Digit |
d |
Extracts the day component. |
PaddedDigit |
dd |
Extracts the day component. |
RomanNumeral |
d:RN |
Extracts the day component. |
RomanNumeral |
dd:RN |
Extracts the day component. |
Usage Example
You can use these tokens with a parser to extract specific date components:
var parser = new YearMonthParser();
(int year, int month) = parser.Parse("2025-08", "yyyy-MM");
Console.WriteLine($"Year: {year}, Month: {month}");
Parsing a Day of Year Format
var parser = new YearDatParser();
(int year, int dayOfYear) = parser.Parse("2025-256", "yyyy-jjj");
Console.WriteLine($"Year: {year}, Day of Year: {dayOfYear}");