Wiki iso week




















Skip to content. Star Branches Tags. Could not load branches. Could not load tags. Latest commit. Git stats 71 commits. Failed to load latest commit information. View code. ISO Week Reference.

Week year , week All arguments are required. Arguments should be ints. Other constructors, all class methods: classmethod Week. Objects representing a week. Navigation Project description Release history Download files. Project links Homepage. Maintainers gisle. Project description Project details Release history Download files Project description The isoweek module provide the class Week.

Week year , week All arguments are required. Arguments should be ints. Other constructors, all class methods: classmethod Week. Note that weeks always stringify back in the former and more compact format.

Instance attributes read-only : Week. Instance methods: Week. Day 0 is Monday. For example Week , 8. Project details Project links Homepage. Download files Download the file for your platform. If you check all of the other dates, especially those during the transition weeks where the year changes, you'll find that the formula works correctly in that the first week of every ISO Year contains the first Thursday of the year.

You'll find out that leap years are also handled correctly. One contains the number of days that have occurred since the first day of January, and the other represents the time of day.

That means that the first day of January, can be represented by a "0". This underlying number is referred to as a "Date Serial Number".

It also turns out that the first of January, was a Monday as is 01 January if you need to change the calculation to handle dates prior to Let's look at the part of the formula I'm talking about. Note that the Date and DOW columns are formatted just to make them prettier in this article. This also has the pleasant side effect of stripping off any time that may be part of the Date column because of the conversion to an Integer actually, it sets the time to "midnight" making a "whole day".

What we end up with is the number of whole weeks since 01 Jan We multiply that result by 7 and what we end up with is the Date Serial Number for the Monday of the week that the Date column is in.

This is a no-brainer. No matter how you swing it, Thursday always come 3 days after Monday in the Gregorian Calendar. Here's the code that demonstrates that. As we've been doing for the other sections, I've left all of the other interim calculations in place just for comparison purposes and will continue to do so in all other examples that follow. Just a reminder.

If you look at the row containing , which just happens to be a Thursday, we can see that there were days in the year and that whole week, which includes part of , has a value of You might think that all we have to do now is divide the DoYThursday value by 7 to get the week number. Nothing could be further from the truth, though. ISO Week Numbers start at "1" so it would seem that just adding "1" to the answer would do the trick. Ah, but wait. If we add "1" to that, would start off at a week number of "2" and as a good friend of mine once said, "That ain't right".

You could go through a bunch of gyrations to figure out that if that first week has a value of "7" that you wouldn't add "1". Instead, let's once again consider the miracle of Integer Math. If we add 6 days to the Date Serial Number before we do the division, it's like adding.

So, the "7" would become "13". In Integer Math, the remainder is simply dropped so we'd end up with the correct answer of "1". Let's look at the opposite end of the spectrum. As we've already seen, that would also result in the correct answer of "1". Looking at the end of , we see the Thursday of that week was also the last day of the year or It all works correctly for everything in between, as well.

We already have this formula in all of the code that we posted. Again, the final formula is listed in this next snippet of code, which is what we started out to begin with. Look carefully at the formula. No where did we violate such a rule. We divided that number by 7, multiplied it by 7, and added 3 to it. That was all Integer Math. We then took that Integer, added 6 to it and divided it by 7. If you know me, you just had to know a million row test was coming next.



0コメント

  • 1000 / 1000