4 ms·
Apropos, you can easily make your own date syntax in Dart: class Month { static const List<String> names = const <String>[ "JAN", "FEB", "MAR", "AP
by reichstein 12y ago
Apropos, you can easily make your own date syntax in Dart:
class Month {
static const List<String> names = const <String>[
"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
];
final int month;
const Month(this.month);
MonthDay operator -(int day) => new MonthDay(month, day);
String toString() => names[month - 1];
}
class MonthDay {
final int month;
final int day;
MonthDay(this.month, this.day);
DateTime operator -(int year) => new DateTime(year, month, day);
String toString() => "${Month.names[month - 1]}-${"$day".padLeft(2, "0")}";
}
const Month JAN = const Month(1);
const Month FEB = const Month(2);
const Month MAR = const Month(3);
const Month APR = const Month(4);
const Month MAY = const Month(5);
const Month JUN = const Month(6);
const Month JUL = const Month(7);
const Month AUG = const Month(8);
const Month SEP = const Month(9);
const Month OCT = const Month(10);
const Month NOV = const Month(11);
const Month DEC = const Month(12);
main() {
print(MAR-25-2015);
}
- jessaustin 12y agoKudos! Truly, Dart has redeeming qualities! Incidentally, this code is the best argument I've seen for "American-style" date writing, with the month first. Or would it be as easy in Dart to override integers with a "DayMonth" operator?