In comp.lang.java.programmer message <week-2016...@ram.dialup.fu-
berlin.de>, Sat, 10 Sep 2016 01:56:51, Stefan Ram <r...@zedat.fu-
berlin.de> posted:
>Dr J R Stockton <repl...@merlyn.demon.co.uk.invalid> writes:
>>Firstly, you need to say, clearly, what your definition of Week
>>Numbering is.
>
> In VBA, there is
>
>Function DatePart
>( Interval As String,
> Date,
> [FirstDayOfWeek As VbDayOfWeek = vbSunday],
> [FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1] )
>
> , with VbDayOfWeek containing
>
>vbUseSystemDayofWeek, vbSunday, vbMonday, vbTuesday, vbWednesday,
>vbThursday, vbFriday, and vbSaturday
>
> and VbFirstweekofyear containing
>
>vbUseSystem, vbFirstJan1, vbFirstFourDays, and vbFirstFullWeek.
>
> So, one can adjust the first day of the week and the rule
> for the first week. Impressive design, but reportedly
>
>VBA.DateTime.DatePart( "ww", #2059-12-30#, vbSunday, vbFirstFourDays )
>
> gives 53, which reportedly is wrong. It reportedly should be 1 instead.
> This reportedly is a bug that reportedly repeats every 28 years.
>
> So, in the end, one still has to program it oneself in VBA
> if one wants a bug-free implementation.
Not _oneself_; it is sufficient for one individual to have done it.
I have done it for VBscript; Java could be different. I see Java has
DateSerial, I suppose equivalent.
See, preferably using a browser which runs VBscript, in
http://web.archive.org/web/20150511204319/http://www.merlyn.demon.co.uk/
vb-date2.htm>.
The 28-year interval only applies between missing leap years; and there
are three errors in every such interval - 3 or 4 per century. Another
error repeats every 400 years; next 2101-01-02.
Microsoft have a bug fix, which that page links to, for the 3/28-year
errors.
For VBscript code written and tested in IE8, see, in the cited page, the
script section beginning with the line
Sub WeekNumJRS(Tdy, YNo, WNo, DoW) '' Tdy is CDate in; Y W D out
Any code giving the ISO 8601 Week Number for a date needs to give also
the year number; and it might as well give also the day-of-week number
(Sunday=7, as earlier established in the Book of Genesis).
If you produce corresponding well-tested similar code in Java, I'd be
pleased to have a URL for it that I may cite. E-address implied by
signature + headers.
--
(c) John Stockton, near London. Mail ?.?.
Stoc...@physics.org
Web < > - FAQish topics, acronyms, and links.