Page 1 of 1

day of the year starts with zero in php

Posted: Sun Jun 29, 2014 12:07 pm
by Shoal
In the control panel ( http://alicorn.elcenia.com/board/ucp.php?i=174 ), you can set your time the your favourite date time format.

My favourite date time format, using PHP letters, happens to be:

Code: Select all

D, Y.m.d (z) H:i:s
Unfortunately, PHP starts counting the days of the year from 0, so that 1st January was the 0th day of the year and today is the 179th day of the year, but I prefer to count days of the year starting with the 1st of January being the 1st day of the year and today being the 180th day of the year, the way Unix date %j works. (insert off topic rant about php and javascript and unix and everybody writing their own date time letters instead of using the perfectly serviceable unix ones that already existed)

I have set my date time format to

Code: Select all

D, Y.m.d (z+1) H:i:s
and this displays as "Sun, 2014.06.29 (179+1) 18:14:15" which is less pleasing than "Sun, 2014.06.29 (180) 18:14:15" would be.

Re: day of the year starts with zero in php

Posted: Sun Jun 29, 2014 1:40 pm
by Marri
Gee, it's almost like there is a whole bookshelf worth of rant-worthy things about PHP! xD And yes, date formats are certainly one of them.

Fun fact: Words with Friends was briefly broken because the date parser the iOS devs wrote couldn't handle Z as a timezone, and we had to force our servers to output +0 instead.

Re: day of the year starts with zero in php

Posted: Sun Jun 29, 2014 2:31 pm
by Shoal
neat fact :)

and, yeah. i know and use php because i have to but I am somewhat looking forward to the day when it's overtaken in popularity by something more appealing.

It'd be one thing if they'd added new functions that the unix datetime letters don't have (I'm fairly certain unix got there first with the datetime letters), but they don't. They just did a random shuffle on the letter for no reason :P Look at the time part of that string, H:i:s, in unix that would be H:M:S.

I thought I could just copy the '%a, %Y.%m.%d (%j) %H:%M:%S' from my window manager's config file where I told it how to display the clock, but no, all* the letters are different.

*all has been redefined to mean 50% of the letters I needed.

Re: day of the year starts with zero in php

Posted: Mon Jun 30, 2014 12:23 am
by Marri
The advent of Heroku has made it reasonably easy for me to use Rails, so now I default to that over PHP, but sadly it's still got a way bigger learning curve for the "general popularity" thing.

I do not actually know when Unix added letters, but I am assuming you're right :) PHP... has ideas sometimes. I get that they decided that "well we want all the options like Jan or January or 1 or 01 and this means having lots of letters", but why this required shuffling letters is beyond me.

Re: day of the year starts with zero in php

Posted: Mon Jun 30, 2014 9:23 am
by Shoal
These are the ones linux uses, from C: http://linux.die.net/man/3/strftime

And here are php's: http://hu1.php.net/manual/en/function.date.php

PHP does seem to have a few that didn't exist in C, but it's missing some too. weird all around :)

I tried googling how long ago strftime was written but I didn't find anything.