Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create dates that are lower than 271800 BC? Like dinosaur time?

This is as low as I can seem to go with javascript date:

var myDate = new Date(0, 0, 1);
myDate.setFullYear("-271800");
alert(myDate);

Anything lower than -271,800 BC throws an invalid date error. Can we go back a million years? Or a billion? Can the date object allow you to describe any date infinitely in the past or future? How might I do something like this?

like image 265
Devin McQueeney Avatar asked Jan 14 '12 05:01

Devin McQueeney


3 Answers

Representing a particular date a million years ago strikes me as meaningless. Julian calendar? Should days of week honor the Babylonian system?

Create your own type for this, decide what you actually need to represent.

--- Updated: This was accepted, so I'll add a few more specific bits. ---

As mentioned in another answer, according to the EcmaScript spec, pg 164 of the fifth edition (link is a .pdf.)

Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript Number values can represent all integers from –9,007,199,254,740,991 to 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.

The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.

But, this is for theoretical dates. It ignores a few pieces of reality. Days were shorter (by 12 seconds) a million years ago, so some JavaScript math would be inaccurate. Days of the week have been determined with different systems. Months have been defined differently. All to say, decide what you really need to represent.

like image 105
Jamie F Avatar answered Nov 11 '22 07:11

Jamie F


The ECMAScript standard requires the Date object to be able to represent any date and time, to millisecond precision, within 100 million days before or after 1/1/1970. This is a range of plus or minus 273,785 years. In order to represent dates outside of this range you would need to implement your own date object that did not operate on millisecond resolution.

like image 3
Dylan Bijnagte Avatar answered Nov 11 '22 05:11

Dylan Bijnagte


You should build your own DateTime for that. It's complexity depends on what you want to achieve...if you want to represent only year, then it is just a simple number...if you want to say what date was the last Sunday in 1 200 000 BC, it is more complex...but have on mind that Sundays didn't exist in that year :)...Gregorian calendar that we use now is introduced 1582 AD, Julian calendar 45 BC (and I'm not sure what was before that). I don't think that even javascript DateTime takes into account that, so setting it to year 271800 BC doesn't make sense.

like image 3
Aleksandar Vucetic Avatar answered Nov 11 '22 06:11

Aleksandar Vucetic