New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
startOf/endOf("week") are not locale aware #727
Comments
I concur:
Moment appears to be ignoring the attempted configuration change. See: http://jsfiddle.net/PPu8E/2/ It also seems to be ignoring the change when applied as part of the supplied moment/lang/en-gb.js configuration (which includes the above "week" config):
and:
Australia subscribes to ISO 8601, via Australian standard AS ISO 8601-2007, which defines the first day of the week to be Monday. Not sure if there's a case for having an en-au.js language config also, or whether you would recommend we just use en-gb. |
I think the problem is in day() function which is not locale-aware. I changed it in my local copy of moment.js, but I'm not sure if it's the right thing to do. Also, weekdays, weekdaysShort and weekdaysMin must be changed in language options (maybe in Language.prototype) or date will be messed like "Sunday 8th April". I'm actually really surprised that this issue was not mentioned earlier by someone. |
Thanks! I ran into the issue trying to get the sunday of last week (for any moment()), and wanted it to be the Sunday irrespective of timezone.
Your comment helped me workaround the issue by pointing me towards the day() function, which I'd overlooked:
|
There is actually a pull request for this bug, but it does not work properly. The correct solution was provided in comments to pull request. |
This comment outlines my proposed fix, but I haven't had time to write it yet. #613 (comment) |
* 'develop' of github.com:timrwood/moment: (53 commits) Use brackets to escape characters Add composer.json fix test and some translations Update it.js Update br.js Fixing indentation Fixing indentation Fixing indentation making startOf('week') use locale week start #727 #634 #699 adding isDST teste fixing zone getter and setter test Updated minified files Added mutations for years Format function now uses "instanceof" on a var rather than "typeof" on that var's call to determine if the variable is a function. This fixes an incompatibility with ClojureScript, which defines String.prototype.call as a function. Corrected Ukrainian and optimized Russian toJSON should not call lang.postformat set hook to add ordinal for Chinese(cn && tw) with modifing the tests Update nn.js Update nn.js Better tests for (iso)weekYear and (iso)weekday and formatting ...
I updated from 2.0 to 2.1, tried 2.7 and this issue is still present.
I cannot update the library to much, the project is 1 year old. |
dow does not work correctly! I have problem too!!! my version is 2.8.4 |
same here. 2.8.4
|
my problem was about bootstrap datepicker and it does not relate to moment |
I'm using moment 2.8.4 and setting locale works for me: $ node
> var moment = require('moment');
undefined
> console.log('Version', moment.version);
Version 2.8.4
undefined
> moment.locale('en', {
> week: {
> dow: 1 // Monday is the first day of the week.
> }
> });
'en'
> moment().startOf('week').format('dddd');
'Monday'
> It also seems that .lang is now deprecated: > moment.lang('en', {
> week: {
> dow: 1 // Monday is the first day of the week.
> }
> });
Deprecation warning: moment.lang is deprecated. Use moment.locale instead. |
@kimmobrunfeldt
EDIT You have to add |
@sahanDissanayake Could you please explain why you set doy to 6? The docs say it should be set to 4 |
oh mate I'm not sure, At the time it seemed to get the job done which is to make Monday the starting day of the week, I have moved on to other projects now. |
@uriklar I got the 6 from here https://github.com/moment/moment/blob/develop/moment.js#L2540 |
is this solved ?? I tried to do |
this is ridiculous, can someone fix this? |
@RomainSF @sahanDissanayake I think you should file separate bug for moment.weekdays() since startOf/endOf("week") work properly. |
I am using version : 2.15.2 and moment().subtract(1, 'weeks').startOf('week') return sunday , and when I change my ip to united states I still get sunday when I expect to get monday. |
@offirpeer Moment supports a wide range of locales, but you will need to explicitly select the locale that is most appropriate for your application in a particular location. A bunch of folks use Also, note that Please open a new issue or reach out on Gitter if you still have questions. |
@offirpeer Use 'isoweek' instead of 'week' if your week starts on Monday. |
Hello,
after using "startOf" the timezone is set to zero. UPDATE : this was not a error! it is correct since there was the hour change at this date. Credits to @reinhrst. |
When I set week.dow to 1 and let's assume it's Saturday 14th April today and I say
It gives me today instead of Monday 8th April.
http://jsfiddle.net/zQx23/
The text was updated successfully, but these errors were encountered: