diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.date.weekDay and goog.date.Date inconsistencies #478

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
goog.date.weekDay (in date.js) enumeration is the following:

goog.date.weekDay = {
  MON: 0,
  TUE: 1,
  WED: 2,
  THU: 3,
  FRI: 4,
  SAT: 5,
  SUN: 6
};

The goog.date.Date.prototype.getDay function is documented as:
@return {goog.date.weekDay} The day of week, US style. 0 = Sun, 6 = Sat.

This is inconsistent.  In fact, the following is true:
var d = new goog.date.Date('Thu 5th Jan, 2012').getDay()
d === goog.date.weekDay.FRI; // Its THU not FRI, this should not be true

goog.date.Date.prototype.getIsoWeekday is consistent with the enumeration; i.e:
var d = new goog.date.Date('Thu 5th Jan, 2012').getIsoWeekday()
d === goog.date.weekDay.THU; // Correct

getIsoWeekday does not return a {goog.date.weekDay}, it just returns a 
{number}.  I think perhaps it should be getIsoWeekday that returns a 
goog.date.weekDay and getDay should just return a {number}.

When looking at this also check goog.i18n.DateTimeSymbols.WEEKDAYS as this also 
has SUN as 0.

No patch attached as this could be very delicate especially when dealing with 
existing code that relies on the goog.date.weekDay enumeration.

Original issue reported on code.google.com by guido.tapia@gmail.com on 20 Jun 2012 at 1:09

GoogleCodeExporter commented 8 years ago
I've just been bitten by this as well. Could we at least change the docs? That 
way in the future people don't read them and try to implement logic around the 
the result of .getDay and goog.date.weekDay.

Original comment by tim.vis...@gmail.com on 23 Oct 2013 at 6:26

GoogleCodeExporter commented 8 years ago
The return type of getIsoWeekday has been updated.

Original comment by joelt...@google.com on 20 Aug 2015 at 10:31