Re: [PHP] Some date() oddities

2013-01-09 Thread Jani Ollikainen

On 9.1.2013 12:22, Arno Kuhl wrote:

Both %U and %W seem to return what you want, using strftime.  I'd guess that
date would also have flags for these.


No. That's one thing I've wondered sometimes.

According to documentation:

strftime has:
Week--- ---
%U 	Week number of the given year, starting with the first Sunday as the 
first week 	13 (for the 13th full week of the year)
%V 	ISO-8601:1988 week number of the given year, starting with the first 
week of the year with at least 4 weekdays, with Monday being the start 
of the week 	01 through 53 (where 53 accounts for an overlapping week)
%W 	A numeric representation of the week of the year, starting with the 
first Monday as the first week 	46 (for the 46th week of the year 
beginning with a Monday)


date has:
Week--- ---
W 	ISO-8601 week number of year, weeks starting on Monday (added in PHP 
4.1.0) 	Example: 42 (the 42nd week in the year)


Also then ISO-8601 week number is kind of mixed, or is older iso
week something different than in 1988 version of the standard=
By description they both %W and W do the same, but other one
is ISO-8601 and in strftime ISO-8601:1988 is %V which is different.

Or is it so that strftime %V is same as date's W, both are really the
iso week's but description for date forgets to mention about that
"at least 4 weekdays".

So at least someone could fix the documentation to be exact to
one don't have to guess or rtfs.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Some date() oddities

2013-01-09 Thread Arno Kuhl
On Tue, 8 Jan 2013, Arno Kuhl wrote:

> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52

I'm not that familiar with date, I tend to use strftime myself (no idea why
there's both).  Sounds like date's W is equivalent to strftime's %V which
does indeed return "01" for this date as there's at least 4 days of the new
year in that particular week.

Both %U and %W seem to return what you want, using strftime.  I'd guess that
date would also have flags for these.

Cheers,
Geoff.
--

Thanks Geoff, that's what I was looking for.

Cheers
Arno


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Some date() oddities

2013-01-08 Thread Geoff Shang

On Tue, 8 Jan 2013, Arno Kuhl wrote:


Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
1356952332) I calculate a week number:

$ux_date = 1356952332;

$weeknumber = date("W", $ux_date);   // returns 01 instead of 52


I'm not that familiar with date, I tend to use strftime myself (no idea 
why there's both).  Sounds like date's W is equivalent to strftime's %V 
which does indeed return "01" for this date as there's at least 4 days of 
the new year in that particular week.


Both %U and %W seem to return what you want, using strftime.  I'd guess 
that date would also have flags for these.


Cheers,
Geoff.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Some date() oddities

2013-01-08 Thread Sebastian Krebs
Hi,

Workaround for what? The 31st of december is the first week of the
ISO8601-year 2013. That has nothing to do with PHP, date(), or any warnings
somebody left in the comments. Thats the way ISO8601 is defined:
http://en.wikipedia.org/wiki/ISO_8601#Week_dates

Regards,
Sebastian


2013/1/8 Arno Kuhl 

> I've bumped into an odd result with the date() function that I can't make
> sense of.
>
>
>
> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52
>
>
>
> I found some warnings regarding ISO8601 for this in the user notes for the
> date() function in the PHP manual but couldn't see how this is managed in
> code, does anyone know of a workaround for this?
>
>
>
> Cheers
>
> Arno
>
>
>
>
>
>


-- 
github.com/KingCrunch


Re: [PHP] Some date() oddities

2013-01-08 Thread Daniel Brown
On Tue, Jan 8, 2013 at 3:43 PM, Arno Kuhl  wrote:
> I've bumped into an odd result with the date() function that I can't make
> sense of.
>
> Starting with a unix timestamp for 31 December 2012 13:12:12 (which is
> 1356952332) I calculate a week number:
>
> $ux_date = 1356952332;
>
> $weeknumber = date("W", $ux_date);   // returns 01 instead of 52

Because, technically, 31 December was the second date of the
*fifty-third* week of 2012.  However, because the majority of the week
falls in 2013, it's rounded-in with that.

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php