by Someone1234 · 11y ago · 0 comments
new Date(2015, 1, 1)
Guess what date that object represents (hint: It isn't January 1st 2015).http://stackoverflow.com/questions/1969442/whats-wrong-with-...
Actually I think it's pretty terrible how few languages have literal expressions for dates. Once you have to type "new Date(", it's not much more annoying to have to remember that January is zero.
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);
}http://www.cplusplus.com/reference/ctime/tm/
tm_mday = day of month (1-31) tm_mon = months since January (0-11)
Which AFIAK goes all the way back to POSIX standard.
The real problem is that JavaScript as higher level language decided to inherit this awkward convention instead of making their own, consistent rules.
Given the time it took to create the first JS implementation, it is no wonder that some shortcuts were taken.
new Date(Heisei, 27, 1, 1)The problem is not with parameter ordering. Year and day are literal, month is zero indexed. So you wind up with (month -1) representing the actual month.
It seems to me that you are not doing your homework and studying hard to get things done professionally.