[...] Let v be ToPrimitive(value). If Type(v) is String, then Parse v as a date, in exactly the same manner as for the parse method (15.9.4.2); let V be the time value for this date. Else, let V be ToNumber(v). Set the [[PrimitiveValue]] internal property of the newly constructed object to TimeClip(V) and return. </>
Si j'en crois la doc, le Date.parse() sera fait automatiquement si rb_date est de type String.
Donc : js_date = new Date(rb_date);
???
???
Dans l'autre sens maintenant, ruby, enfin le driver pour MongoDB (dans MongoDB les dates sont en iso)demande une date utc...
donc j'ai js_date un objet Date en js. pour convertir dans ce que (ruby seulement?) dit être un format UTC, je fais :
js_date_utc_string = js_date.toISOString();
Ça me semble correct.
Le 23/10/2014 12:12, Une Bévue a écrit :
C'est curieux tout de même que Date.parse(str) retourne un nombre et pas
une date ?
Ce n'est pas curieux, c'est ce que définit la norme :
[...]
it returns a Number, the UTC time value corresponding to the date and time
</>
<http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.1>
15.9.1.1 Time Values and Time Range
[...]
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.
</>
en entrée j'ai :
var rb_date = '2014-10-23T09:26:25.601Z';
(une date provenant de MongoDB à travers le driver ruby)
là, en js, je dois faire :
js_date = new Date(Date.parse(rb_date));
pour avoir un objet Date en js.
<http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3.2>
15.9.3.2 new Date (value)
[...]
Let v be ToPrimitive(value).
If Type(v) is String, then
Parse v as a date, in exactly the same manner as for the parse
method (15.9.4.2); let V be the time value for this date.
Else, let V be ToNumber(v).
Set the [[PrimitiveValue]] internal property of the newly
constructed object to TimeClip(V) and return.
</>
Si j'en crois la doc, le Date.parse() sera fait automatiquement si
rb_date est de type String.
Donc :
js_date = new Date(rb_date);
???
???
Dans l'autre sens maintenant, ruby, enfin le driver pour MongoDB (dans
MongoDB les dates sont en iso)demande une date utc...
donc j'ai js_date un objet Date en js.
pour convertir dans ce que (ruby seulement?) dit être un format UTC, je
fais :
[...] Let v be ToPrimitive(value). If Type(v) is String, then Parse v as a date, in exactly the same manner as for the parse method (15.9.4.2); let V be the time value for this date. Else, let V be ToNumber(v). Set the [[PrimitiveValue]] internal property of the newly constructed object to TimeClip(V) and return. </>
Si j'en crois la doc, le Date.parse() sera fait automatiquement si rb_date est de type String.
Donc : js_date = new Date(rb_date);
???
???
Dans l'autre sens maintenant, ruby, enfin le driver pour MongoDB (dans MongoDB les dates sont en iso)demande une date utc...
donc j'ai js_date un objet Date en js. pour convertir dans ce que (ruby seulement?) dit être un format UTC, je fais :