<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>22714</bug_id>
          
          <creation_ts>2013-07-17 22:33:09 +0000</creation_ts>
          <short_desc>Misuse of Date object</short_desc>
          <delta_ts>2013-07-31 21:29:10 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne">annevk</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>cam</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>mounir</cc>
    
    <cc>philipj</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>90901</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-07-17 22:33:09 +0000</bug_when>
    <thetext>Per https://mail.mozilla.org/pipermail/es-discuss/2013-July/032038.html HTMLMediaElement.startDate should really have used DOMTimeStamp instead.

Can we still change that?

Also, it might be that most of HTMLInputElement.valueAsDate doesn&apos;t strictly require Date objects either. I have not investigated that in detail however.

The property of obj.attribute != obj.attribute seems horribly wrong though, so maybe HTMLInputElement.valueAsDate should be changed anyway.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90905</commentid>
    <comment_count>1</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2013-07-17 23:43:53 +0000</bug_when>
    <thetext>If HTMLInputElement exposed the time/date value as milliseconds since the epoch, then it&apos;s a bit awkward for the author to have to construct a Date object from it so that they can easily extract, year, month, day, etc.

I must admit this is the first I have heard that Date objects are not good for representing times/dates without timezone information.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90906</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-07-18 00:15:50 +0000</bug_when>
    <thetext>Note that further on in the thread it is pointed out that currently Date objects are simply a wrapper for a timestamp and do not contain timezone information.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90936</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-18 17:58:33 +0000</bug_when>
    <thetext>startDate is a time on UT1. That&apos;s what Date represents. What&apos;s the problem here?
I&apos;m confused.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91206</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-07-24 06:14:54 +0000</bug_when>
    <thetext>The problem is obj.startTime != obj.startTime. In addition, the JS community doesn&apos;t want us to use Date but just use DOMTimeStamp (i.e. a number).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91228</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-24 16:12:46 +0000</bug_when>
    <thetext>Well we can easily solve obj.startTime != obj.startTime, just cache the Date object between changes to the timeline offset.

I don&apos;t understand why Date would be the wrong thing to return here. It seems eminently ideal for this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91229</commentid>
    <comment_count>6</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-07-24 17:03:26 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8083.
Check-in comment: Make media.startDate return the same object until the time changes. (also, typo in dependencies section)
http://html5.org/tools/web-apps-tracker?from=8082&amp;to=8083</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91299</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-26 00:15:20 +0000</bug_when>
    <thetext>So the only argument now seems to be &quot;the JS community doesn&apos;t want us to use Date but just use [...] a number&quot;. Can you elaborate on that argument?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91302</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-07-26 02:03:19 +0000</bug_when>
    <thetext>What you are currently doing violates IDL. The semantics from a developer perspective are weird, because a Date is not immutable, but mutating the object&apos;s state will not affect anything.

I think the JS perspective is to not expose a more complicated thing when something much simpler is sufficient. If you disagree with this I&apos;d encourage you to engage on es-discuss.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91332</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-26 22:21:54 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; What you are currently doing violates IDL.

How so?


&gt; The semantics from a developer perspective are weird, because a Date is not 
&gt; immutable, but mutating the object&apos;s state will not affect anything.

Well that&apos;s why it was returning a unique value before, but you didn&apos;t like that either. I&apos;ve gone back to the old behaviour.


&gt; I think the JS perspective is to not expose a more complicated thing when
&gt; something much simpler is sufficient. If you disagree with this I&apos;d
&gt; encourage you to engage on es-discuss.

I&apos;m happy to leave the spec as is. I don&apos;t understand the problem here. We could always return &quot;something simpler&quot; — should we return the whole DOM as just a string, rather than elements? That makes no sense to me.


I think the fact that (new Date(0)) != (new Date(0)) is really just as much of a problem as the fact that video.startDate != video.startDate. Returning a number is dumb, since it&apos;s not a number — it&apos;s very specifically a date. A Date object is just a number representing a date wrapped in a useful API for managing this kind of thing. It seems like exactly what is needed here.

If someone has a concrete problem with this, they should file a bug (or reopen this one) rather than going through a proxy without explaining to the proxy what the actual problem is.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91333</commentid>
    <comment_count>10</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-07-26 22:22:03 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8094.
Check-in comment: Revert r8083, since it leads to weird behaviour worse than just returning a new object each time. (It seems this isn&apos;t implemented by anyone yet anyway.)
http://html5.org/tools/web-apps-tracker?from=8093&amp;to=8094</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91338</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-07-26 23:57:06 +0000</bug_when>
    <thetext>I think the specific complaint is that the Date object is not a useful API and that a number is typically easier to work with. Again though, I&apos;m relaying what the developer community and the committee in charge of JavaScript feel is the best thing. If this isn&apos;t implemented we should definitely switch to DOMTimeStamp or maybe something that allows millisecond precision like the other parts of the media API.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91372</commentid>
    <comment_count>12</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2013-07-29 06:52:50 +0000</bug_when>
    <thetext>It might be useful to have a look at what the underlying data exposed through .startDate is. For WebM &lt;http://www.webmproject.org/docs/container/&gt;, I believe it would be DateUTC, which makes a lot of sense to represent as a Date, IMHO.

As an aside, Matroska &lt;http://matroska.org/technical/specs/index.html&gt; dates is a &quot;signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium&quot; so conversion is needed in any case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91386</commentid>
    <comment_count>13</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-29 19:51:41 +0000</bug_when>
    <thetext>(In reply to comment #11)
&gt; I think the specific complaint is that the Date object is not a useful API

How is it a less useful API for exposing a Date and Time than Number?

I really don&apos;t understand. Could you give a concrete example of how it&apos;s less useful? (Note that Date can be converted to Number trivially. It has a valueOf.)


&gt; I&apos;m relaying what the developer community and the committee in charge of
&gt; JavaScript feel is the best thing.

Can you provide URLs of where the developer community is indicating concern over startDate being exposed as a date? I would love to see what developers are trying to do with it that they would find more easy if it was a Number object than a Date object.


&gt; If this isn&apos;t implemented we should definitely switch to DOMTimeStamp or maybe
&gt; something that allows millisecond precision

Date allows millisecond precision already.


I&apos;m not a priori objecting to changing the API. But I *am* objecting to changing the API based on no reasoning whatsoever.

Currently the benefits of each approach are as follows:

  - Returning a Number
     + you can find the difference between them by subtraction.
     + you can compare them using &lt; and &gt;.
     + you can compare the two video&apos;s startDates for equality using x==y 
       instead of having to use (x&lt;=y)&amp;&amp;(x&gt;=y).

  - Returning a Date
     + has a useful API for manipulating Dates, e.g. you can find out what 
       the time is in the user&apos;s time zone and render it as such trivially,
       as well as comparing individual parts of it like the time or month.
     + you can find the difference between them by subtraction.
     + you can compare them using &lt; and &gt;.

In practice, the use cases for startDate are three-fold, as far as I can tell:

 1. Displaying a string to the user (typically just the time), on the seek bar.
 2. Subtracting the time from another time to find an offset for adjusting out-
    of-band timings (e.g. displaying a synchronised slide show)
 3. Checking which of two streaming videos started earlier.

These three use cases map exactly to the &quot;pros&quot; of Date, and more of them are handled by Date than by number. The ability to compare dates _for equality_ more easily using numbers than Dates doesn&apos;t affect any of the use cases.


If you really do want to compare two Date objects x and y for equality, there&apos;s a multitude of ways to do so:

   (x &lt;= y) &amp;&amp; (y &gt;= x)
   x.valueOf() == y.valueOf()
   x-y == 0
   x-0 == y-0

It&apos;s no different than if you had Number objects instead of literal numbers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91467</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-31 17:40:37 +0000</bug_when>
    <thetext>Other benefits of using Date that I hadn&apos;t thought of, based on the feedback here:

   https://twitter.com/annevk/status/362017983461212160

     + it has a better representation when serialising to JSON (it converts to
       a string that looks like a date, not an opaque number).
     + it has an API to convert to ISO8601 format.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91479</commentid>
    <comment_count>15</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-31 21:28:57 +0000</bug_when>
    <thetext>Since the only disadvantage of using a Date is that it&apos;s confusing that Date attributes return objects that aren&apos;t live (mutating the object doesn&apos;t affect the underlying object, and the &quot;readonly&quot;ness doesn&apos;t propagate to the Date itself), I&apos;ve changed the spec to use a method instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91480</commentid>
    <comment_count>16</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-07-31 21:29:10 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8113.
Check-in comment: Change startDate to a method to avoid the confusion of it being mutable.
http://html5.org/tools/web-apps-tracker?from=8112&amp;to=8113</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>