Skip to content

Commit

Permalink
fix: incorrect milliseconds on ideal time pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
gbassisp committed May 20, 2024
1 parent 70a94c7 commit b650fdd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/src/any_date_rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ final _s = _separatorPattern;
// '(${usedSeparators.reduce((v1, v2) => '$v1|$v2')})+';
// avoid const because this will be updated soon-ish
String get _timeSep => ':';
final _hmPattern = '$_hourPattern$_timeSep$_minutePattern';
final _hmsPattern = '$_hmPattern$_timeSep$_secondPattern';
final _hmsMsPattern = '$_hmsPattern.$_microsecondPattern';
final _hmIdeal = '$_hourPattern$_timeSep$_minutePattern';
final _hmsIdeal = '$_hmIdeal$_timeSep$_secondPattern';
final _hmsMsIdeal = '$_hmsIdeal\\.$_microsecondPattern';

/// ideal time expressions that uses only ':' as separators
@internal
final idealTimePatterns = [
_hmsMsPattern,
_hmsPattern, // + r'(\D|$)',
_hmPattern,
_hmsMsIdeal,
_hmsIdeal, // + r'(\D|$)',
_hmIdeal,
_hourPattern,
];

/// original patterns used in implementation that allows non-sense separators,
/// such as "-"
/// this is not entirely supported because was never tested for "h" or "min"
/// separators
final _timePatterns = idealTimePatterns.map((e) => e.replaceAll(_timeSep, _s));
final _hmPattern = '$_hourPattern$_s$_minutePattern';
final _hmsPattern = '$_hmPattern$_s$_secondPattern';
final _hmsMsPattern = '$_hmsPattern.$_microsecondPattern';

final _timePatterns = [
_hmsMsPattern,
_hmsPattern, // + r'(\D|$)',
_hmPattern,
_hourPattern,
];

/// default parsing rule from dart core
DateTime? dateTimeTryParse(String formattedString) =>
Expand Down

0 comments on commit b650fdd

Please sign in to comment.