This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21309 - Date object doesn't allow difference or add or other math
Summary: Date object doesn't allow difference or add or other math
Status: RESOLVED INVALID
Alias: None
Product: WHATWG
Classification: Unclassified
Component: JavaScript (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 enhancement
Target Milestone: Unsorted
Assignee: Mathias Bynens
QA Contact: sideshowbarker+javascript
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-16 04:37 UTC by Jim Michaels
Modified: 2014-06-21 12:52 UTC (History)
1 user (show)

See Also:


Attachments

Description Jim Michaels 2013-03-16 04:37:50 UTC
the ecmascript 262 reference that since the constructor returns a TimeClip in milliseconds (I assume this is some sort of timestamp, the definition of what a TimeClip was exactly, and what its range is, its meaning, and other necessities wasn't given).
I had assumed that since it returns a TimeClip in ms, it must somehow be differenceable. yes? no. it is not.

<h2>DTV <s>Feb 17, 2009</s> June 12, 2009 over-the-air Transition<span id="o1"></span></h2>
<h2>DTV March 18, 2009 Cable ch32-71 Transition<span id="o2"></span></h2>
<script>
function liveupdate() {
	var dnow = new Date();
	var d1 = new Date(2019,6-1,12,5+12); //june 12,2009 5pm
	var diff = d1 - dnow;
	document.getElementById( 'o1' ).innerHTML = '(' + diff.getFullYear() + ' years ' + diff.getMonth() + ' months ' + (diff.getDate()-1) + ' days ' + diff.getHours() + ':' + diff.getMinutes() + ':' + diff.getSeconds() + '.' + diff.getMilliseconds() + ')';
	d1 = new Date(2019,3-1,18,5+12);//march 18th, 2009 5pm
	diff = d1 - dnow;
	document.getElementById( 'o2' ).innerHTML = '(' + diff.getFullYear() + ' years ' + diff.getMonth() + ' months ' + (diff.getDate()-1) + ' days ' + diff.getHours() + ':' + diff.getMinutes() + ':' + diff.getSeconds() + '.' + diff.getMilliseconds() + ')';
}
setInterval(liveupdate,200);
</script>	  

this code gives its first error in firebug under firefox "type error: diff.getFullYear is not defined". I am sure it would balk at the rest of the diff method calls from the Date object stuff if it doesn't like this, which should be defined. I am not sure why this isn't defined. I even tried changing the 2009 to 2019 with no change of error message. one should think that this kind of code would work. or that there would be some sort of acceptable functions for doing time differences in javascript. but there aren't.

for 2009, today diff would be a negative 0-based time difference value.

I am sure we all would appreciate some time difference/addition and calculation functions in which the Date object and TimeClip() and related stuff can be used.

ISO 8601 (2004) defines some time format strings for time differences "intervals" in either chapter 3 or 4 I think. really it's kind of scattered all around the document, because in a hard to find place in the document, the spec allows for appending milliseconds using a , or . as a fraction of a second. so really you are defining a second, for instance I think ...TH12M59S23,999 or T12:59:23.999
I hope this helps you give better resolution in your ISO strings in javascript for JSON and Date objects (see ecmascript 262 15.9.5.43, 15.9.4.2).
this is one method of I/O.

but I would also like .getDays() (0-based total number of days), all of the usual calendar functions like 0-based .getFullYear() and hopefully can handle negative numbers, 0-based getMonth(), 1-based .getDate(), in my diff/add functions and/or my Date object (Date object would be more convenient).

the specification should say these things.

what this is useful for: countdown timers, countup timers, stopwatches, kitchen timers,games (though I have no use for games, they do seem to be popular right now).

thank you.
Comment 1 Jim Michaels 2013-03-16 05:08:52 UTC
hmm. the getDate() should be 0-based as well.
Comment 2 Mathias Bynens 2014-06-21 12:51:47 UTC
This is outside the scope of the JavaScript / Web ECMAScript spec. See <http://javascript.spec.whatwg.org/#goals>.

To propose new features to the ECMAScript language, please file a bug on https://bugs.ecmascript.org/.