If you're using YYYY in your JVM service or %G in anything, fix it now
The single character G instead of Y took down Twitter's API today.
If you're using YYYY in your JVM service or %G in anything, fix it now. You're very likely using the wrong year format.
date Mon Dec 29 00:44:45 EST 2014 date -u "+%G" 2015
ISO 8601 week numbering has 2015 start this week.
74 comments
[ 3.8 ms ] story [ 135 ms ] threadAlso https://twitter.com/jmhodges/status/549431554879938560 :
"(The correct formats are "yyyy" and "%Y". Yes, this matters and is happening right now. "Week-based years" are a thing.)"
If you're going to throw something like this out on the internet, I would like it to be more detailed. Just blasting it out on Twitter is pretty useless.
Reproduction: `date -u "+%G"`, sorry but that does EXACTLY what it's suppose to: [http://pubs.opengroup.org/onlinepubs/009695399/functions/str...].
Depending on your operating system it's even documented. OpenBSD has a pretty good documentation for it, while Mac OS X is somewhat lacking, but to the point where you wouldn't use it without checking what it actually means.[http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/...]
Why would you even pick %G if that wasn't what you meant, %Y seems more obvious. Using YYYY I can understand, it's a bit of gotcha that YYYY is one thing and yyyy is something less. It even test correctly more often than not.
[0] http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDat...
The year number of the ISO week very often differs from the Gregorian year number for dates close to 1 January. For example, 29 December 2014 is ISO 2015-W1-1, i.e., it is in year 2015 instead of 2014.
http://en.wikipedia.org/wiki/ISO_week_date
Specifically, you should be using +%Y instead of +%G when passed into date, and 'yyyy' instead of 'YYYY' when used in Java.
Thanks.
I also remember at one startup when I asked the payroll guy how many pay periods there were that year, he scoffed "26, it's always 26." Well, not with years having fractionally more than 26 ^H^H^H 52 weeks there aren't.
http://www.dir.ca.gov/dlse/faq_paydays.htm
Do you know how they get away with this, or have any other insight?
That is my only guess...
From here: http://www.dir.ca.gov/dlse/Glossary.asp?Button1=P#profession...
professional exemption
A person employed in a professional capacity means any employee who meets all of the following requirements:
Who is licensed or certified by the State of California and is primarily engaged in the practice of one of the following recognized professions: law, medicine, dentistry, optometry, architecture, engineering, teaching, or accounting, or
If I had to hazard a guess but I would suspect it's because people in those professions are expected to be salary. Salary is easier to budget out in longer increments as the base pay amounts per pay period typically don't vary. (annual salary / pay periods = pay amount)
For those who work on this day (medical professionals, etc.) the rate is different (being a holiday and all), so they just get paid by the hour, regardless of what they do throughout the year.
Your payroll can now be weekly, biweekly, monthly, or whatever you want: you still get the same amount of money per month. This is nice because you don't get weirdness with things like rent/mortgage payments which are monthly. For example, for those who get paid biweekly, you get two months a year where you get an extra payment. This is silly and leads to more difficult accounting and budgeting.
Monthly is nice, but lots of your expenses are likely one a week-by-week basis: groceries, entertainment, etc.
Weekly is AFAIAC the nicest: it is the easiest to budget because it's as close to the common denominator as possible. However, it is not the LCD, so it still has the weird problem of getting more money in some months vs others.
Of course, changing the calendar isn't a realistic plan anyway (Americans still won't accept the freaking metric system, that's too much change! and of course there would be costs to having a calendar different than the rest of the world, unless we get EVERYONE to change). But making _everyone_ have off is even less realistic. So payroll systems would still probably need to account for the days.
But I do like the idea of a day or two that literally everyone has off, and would subscribe to your newsletter.
Wikipedia confirms "The Islamic calendar is now used primarily for religious purposes, and for official dating of public events and documents in Muslim countries". http://en.wikipedia.org/wiki/Islamic_calendar#Uses
Also, the 'Y' character was a relatively late addition to Java, in v1.7. Before that it was an invalid value.
(edit: This post had originally suggested the post's title be changed to mention Java, thus vitno's reply below)
Why is it useful you might ask: when you order a time-series by week number, or if you are grouping by week numbers, you would need the week number of course. But if the data is spanning over two years, you would need also the year for grouping, because you would add up weeks from different years. If you use week number + current year you get errors around the end of some years.
[0] http://www.calendar-365.com/2015-calendar.html
http://joda-time.sourceforge.net/apidocs/org/joda/time/forma...
http://joda-time.sourceforge.net/field.html#yearOfEra
https://gist.github.com/k0nserv/f53084ebb6a753c4905f
(According to man on Mac OSX for G - "This year is the one that contains the greater part of the week (Monday as the first day of the week)"
Shouldn't that be Mon-Sun? The Sun-Sat week we are currently in is majority 2014, but the Mon-Sun week that started today is majority 2015.
Our example is a couple of activity reports we send to the government where we need to have full weeks and they want calendar years and not budget years[1]. I seem to remember payroll for some uses the same scheme (yep, we pay weekly). Plus some internal reporting the the ISO date makes nice since we have a 2 week break which includes Xmas and New Years.
1) These are a bit of odd ducks actually. Most government reporting we do is based on Federal Fiscal years which start Oct 1. I remember in the 90's one foxbase function that did a similar algorithm except centered on Oct 1 and defined the first day of the week as Sunday.
When reading the docs [1] it's pretty obvious which one should be used so I am left wondering why I ended up with 'o' in my code. I suspect I copy-pasted something from some random blog post or whatever. Serves me right. :(
[1] http://php.net/manual/en/function.date.php