Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The ISO calendar has a range of confusing rules that are likely the source of the issues you face here. In particular, the .NET implementation of <code>GetWeekOfYear</code> (with the parameters you have used) is so similar to ISO that <a href="http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx" rel="nofollow noreferrer">explicit clarifications</a> are required and linked from <a href="http://msdn.microsoft.com/en-us/library/system.globalization.calendarweekrule.aspx" rel="nofollow noreferrer">MSDN</a>. The result is that <code>isocalendar</code> and <code>GetWeekOfYear</code> will produce results that differ [my emphasis]:</p> <blockquote> <p>Specifically ISO 8601 always has 7 day weeks. If the first partial week of a year doesn't contain Thursday, then it is counted as the last week of the previous year. Likewise, <strong>if the last week of the previous year doesn't contain Thursday then its treated like the first week of the next year</strong>. GetWeekOfYear() has the first behavior, but not the second.</p> </blockquote> <p>Some suggestions for correcting <code>GetWeekOfYear</code> are discussed at the link above and also at <a href="https://stackoverflow.com/questions/428957/is-net-giving-me-the-wrong-week-number-for-dec-29th-2008">Is .NET giving me the wrong week number for Dec. 29th 2008?</a> If you actually want to match the <code>GetWeekOfYear</code> behaviour these two links will assist, although you will be applying the reverse transformation to their examples.</p> <p>The most 'Pythonic' way of doing it is to create a function. Nothing particularly special here, except the usual attempt to minimise code by doing things like <code>day &lt; 4</code> rather than <code>day == 1 or day == 2 ...</code> etc.</p> <p>(Of course, all of this is assuming that Python's <code>isocalendar</code> correctly matches the ISO calendar. The documentation seems to suggest that it does, where the <code>GetWeekOfYear</code> explicitly states that it doesn't, so it would seem a reasonable assumption. However, if this is a critical calculation, you will be testing it thoroughly yourself anyway.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload