This is a ported version of https://github.com/wanasit/chrono typescript library
Caution: super slow in debug mode(idk why), but in release it is good
all tests rewritten and passed
It is designed to handle most date/time format and extract information from any given text:
- Today, Tomorrow, Yesterday, Last Friday, etc
- 17 August 2013 - 19 August 2013
- This Friday from 13:00 - 16.00
- 5 days ago
- 2 weeks from now
- Sat Aug 17 2013 18:40:39 GMT+0900 (JST)
- 2014-11-30T08:15:30-05:30
english, russian
chrono:
git:
url: https://github.com/SibirixScrum/dart-chrono.git
ref: '1.0v'
chrono:
git:
url: https://github.com/SibirixScrum/dart-chrono.git
ref: '1.0s'
final result = Chrono.en.casual.parse('An appointment on Sep 12-13'); // now is 2023-09-29
print(result[0].start.date()); // 2023-09-12 12:00:00.000
print(result[0].end?.date()); // 2023-09-13 12:00:00.000
you can also pass PasringOption and ParsingReference
final result = Chrono.en.casual.parse('An appointment on Sep 12-13',referenceDate: DateTime(2025,9,20));
// Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
print(result[0].start.date()); // 2025-09-12 12:00:00.000
print(result[0].end?.date()); // 2025-09-13 12:00:00.000
final result = Chrono.en.casual.parse('An appointment on Sep 12-13',referenceDate: DateTime(2025,9,20),option: ParsingOption(forwardDate: true));
// Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
print(result[0].start.date()); // 2026-09-12 12:00:00.000
print(result[0].end?.date()); // 2026-09-13 12:00:00.000
you can simply pass DateTime or use ParsingReference class
instant?: Date
The instant when the input is written or mentionedtimezone?: string | number
The timezone where the input is written or mentioned. Support minute-offset (number) and timezone name (e.g. "GMT", "CDT"). You can see all suported strings in file timezone.dart
forwardDate
(boolean) to assume the results should happen after the reference date (forward into the future)
timezones
Override or add custom mappings between timezone abbreviations and offsets. Use this when you want Chrono to parse certain text into a given timezone offset. Chrono supports both unambiguous (normal) timezone mappings and ambigous mappings where the offset is different during and outside of daylight savings.
refDate: Date
The reference date of this resultindex: number
The location within the input text of this resulttext: string
The text this result that appears in the inputstart: ParsedComponents
The parsed date components as a ParsedComponents objectend?: ParsedComponents
Similar tostart
date: () => Date
Create a dart DateTime forstart
get: (c: Component) => number | null
Get known or implied value for the componentisCertain: (c: Component) => boolean
Check if the component has a known valuedate: () => Date
Create a dart DateTime- if you want more information you can use
ParsedComponents as ParsingComponent
and get a bunch of extra properties
check original https://github.com/wanasit/chrono