Skip to content
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

How can I extract a coordinated year and week number from a string #698

Closed
mikeymckay opened this issue Mar 28, 2013 · 4 comments
Closed

Comments

@mikeymckay
Copy link

From: http://jsfiddle.net/SvJ8Q/1/

(moment("2012-12-31").year())
=> 2012
(moment("2012-12-31").week())
=> 1
(moment("2013-01-01").week())
=> 1
(moment("2013-11-08").year())
=> 2013
(moment("2013-01-08").week())
=> 2

I understand why the week function returns 1 in the above - but this really coincides with week 1 of year 2013, right? How do I get the year part of the week function?

Maybe there is a better way to achieve what I am after. I have incidents per date from many years. I want to graph the number of incidents by week. But the year/week behavior above will group 12-31-2012 data into the first week of 2012.

@ichernev
Copy link
Contributor

Related to #613
A bit of work is needed to extract the year from weekOfYear function in conjunction with the week number to provide all these format tokens described in the bottom.

@mikeymckay
Copy link
Author

I realize this isn't using the week standard, but here's was my workaround to get what I needed:

            year = date.year()
            week = Math.ceil(date.dayOfYear() / 7)

@ichernev
Copy link
Contributor

There are local week numbers -- for all locales the first day of the week is defined, as well as how to determine which is the first week of a year. There is also an isoWeek that follows some standard, but the isoYear is missing.

@ichernev
Copy link
Contributor

This is fixed in 699f3ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants