-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from gbassisp/fix/0.1-conflicts
Fix/0.1 conflicts
- Loading branch information
Showing
6 changed files
with
158 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
|
||
## 0.1.16 | ||
|
||
- Fix conflicts with version 1.x | ||
|
||
## 0.1.15 | ||
|
||
- Fix `dd-MMM-yy` format parsing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// TODO(gbassisp): promote this to lib/ once we enable support for locale | ||
import 'package:any_date/any_date.dart'; | ||
import 'package:any_date/src/extensions.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:intl/locale.dart'; | ||
import 'package:lean_extensions/dart_essentials.dart'; | ||
|
||
extension LocaleExtensions on Locale { | ||
AnyDate get anyDate => AnyDate( | ||
info: DateParserInfo( | ||
dayFirst: !usesMonthFirst, | ||
yearFirst: usesYearFirst, | ||
months: [...longMonths, ...shortMonths], | ||
weekdays: [...longWeekdays, ...shortWeekdays], | ||
), | ||
); | ||
|
||
static final _date = DateTime(1234, 5, 6, 7, 8, 9); | ||
|
||
String get _yMd => DateFormat.yMd(toString()).format(_date); | ||
|
||
// DateParserInfo get parserInfo => DateParserInfo( | ||
// yearFirst: usesYearFirst, | ||
// dayFirst: !usesMonthFirst, | ||
// months: [...longMonths, ...shortMonths], | ||
// weekdays: [...longWeekdays, ...shortWeekdays], | ||
// ); | ||
|
||
bool get usesNumericSymbols { | ||
try { | ||
usesMonthFirst; | ||
usesYearFirst; | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
|
||
bool get usesMonthFirst { | ||
final formatted = _yMd; | ||
final fields = formatted.split(RegExp(r'\D')) | ||
..removeWhere((element) => element.trim().tryToInt() == null); | ||
final numbers = fields.map((e) => e.toInt()); | ||
|
||
assert( | ||
numbers.contains(5), | ||
'could not find test date in $this: $formatted', | ||
); | ||
|
||
final monthIndex = numbers.indexOf(5); | ||
final dayIndex = numbers.indexOf(6); | ||
|
||
assert( | ||
monthIndex != null && dayIndex != null, | ||
'month and day must both be present in $this: $formatted', | ||
); | ||
return monthIndex! < dayIndex!; | ||
} | ||
|
||
bool get usesYearFirst { | ||
final formatted = _yMd; | ||
final fields = formatted.split(RegExp(r'\D')) | ||
..removeWhere((element) => element.trim().tryToInt() == null); | ||
final numbers = fields.map((e) => e.toInt()); | ||
|
||
assert( | ||
numbers.contains(1234), | ||
'could not find test date in $this: $formatted', | ||
); | ||
|
||
final yearIndex = numbers.indexOf(1234); | ||
final monthIndex = numbers.indexOf(5); | ||
|
||
assert( | ||
yearIndex != null && monthIndex != null, | ||
'month and year must both be present in $this: $formatted', | ||
); | ||
return yearIndex! < monthIndex!; | ||
} | ||
|
||
Iterable<Month> get longMonths sync* { | ||
final format = DateFormat('MMMM', toString()); | ||
for (final i in range(12)) { | ||
final m = i + 1; | ||
final d = DateTime(1234, m, 10); | ||
yield Month(number: m, name: format.format(d)); | ||
} | ||
} | ||
|
||
Iterable<Month> get shortMonths sync* { | ||
final format = DateFormat('MMM', toString()); | ||
for (final i in range(12)) { | ||
final m = i + 1; | ||
final d = DateTime(1234, m, 10); | ||
yield Month(number: m, name: format.format(d)); | ||
} | ||
} | ||
|
||
Iterable<Weekday> get longWeekdays sync* { | ||
final format = DateFormat('EEEE', toString()); | ||
for (final i in range(7)) { | ||
final w = i + 1; | ||
final d = DateTime(2023, 10, 8 + w); | ||
yield Weekday(number: w, name: format.format(d)); | ||
} | ||
} | ||
|
||
Iterable<Weekday> get shortWeekdays sync* { | ||
final format = DateFormat('EEE', toString()); | ||
for (final i in range(7)) { | ||
final w = i + 1; | ||
final d = DateTime(2023, 10, 8 + w); | ||
yield Weekday(number: w, name: format.format(d)); | ||
} | ||
} | ||
} | ||
|
||
extension _ListExtension<T> on Iterable<T> { | ||
int? indexOf(T element) { | ||
for (final i in range(length)) { | ||
if (elementAt(i) == element) { | ||
return i; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |