Am I missing something or Date.WeekOfYear() reports 53 weeks for 2016?
dim d as new date(2016, 12, 31)
dim w as integer = d.weekOfYear
w = 53 but it should be 52.
I know it calculate the weeks using Sunday as the first day of week, but even with this changes nothing due 2016-12-31 is Saturday.
2016 does have 53 Saturdays… and Saturday is used for weekofyear in Xojo, not Sunday
and per the LR, “Week #1” might be “short”
and even http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2016 says there are 52 weeks in 2016
but I believe it was discussed elsewhere that XOJO method and ISO method were NOT the same, and someone posted code to calculate the ISO method
Thanks Dave, this explain why Xojo is wrong.
Still it reports a wrong value…
53 is the correct value as far as XOJO is concerned… its just not the correct answer as far as the ISO is concerned
WeekOfYear can be more than 52 as the first week might be short. Like what Dave said. Now which day you use to “start” the week and “define” the week number, varies from implementation to implementation.
[quote]Date: 19.06.12 00:48 (Mon, 18 Jun 2012 19:48:30 -0400)
From: Greg O’Lone
WeekOfYear is counted based on the number of days since January 1st of the year you are measuring. Thusly:
January 1-7 = Week 1
January 8-14 = Week 2
THe day of week does not affect the week of year calculation.
Real Software, Inc.[/quote]
And I agree, WeekOfYearISO should be added to the date class
I doubt the global Date class will get that love. At best it might make it Xojo.Core.Date. There is currently no WeekOfYear Property. http://developer.xojo.com/xojo-core-date It should probably make it into a Feedback request.
Are you connecting to a database? If so it likely has date functions that’ll give you what you want, e.g:
Postgres: SELECT EXTRACT(WEEK FROM TIMESTAMP ‘2016-12-31’);
Firebird: SELECT EXTRACT(WEEK FROM DATE ‘2016-12-31’) AS wkno FROM rdb$database;
MySQL: SELECT WEAKOFYEAR(‘2016-12-31’);
I imagine SQLite has it too if you do a little research
There is already a feature request feedback://showreport?report_id=11024