add -isoYear

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37377 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-11-18 15:19:23 +00:00
parent ae9f830228
commit 6781e92ac5
3 changed files with 34 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2013-11-18 Wolfgang Lux <wolfgang.lux@gmail.com>
* Headers/GNUstepBase/NSCalendarDate+GNUstepBase.m:
* Source/Additions/NSCalendarDate+GNUstepBase.m:
Add -isoYear method for compatibility with -weekOfYear
2013-11-07 Riccardo Mottola <rm@gnu.org>
* Source/GSFormat.m

View file

@ -38,6 +38,16 @@ extern "C" {
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
@interface NSCalendarDate (GNUstepBase)
/** According to the ISO definition of a week, each year begins with the
* Monday of the week containing the 4th of January. If we a have a date
* early in January or late in December we therefore may need to adjust
* the year to match the definition of a week.<br />
* This method is used to return the ISO year rather than the normal
* calendar year.
*/
- (NSUInteger) isoYear;
/**
* The ISO standard week of the year is based on the first week of the
* year being that week (starting on monday) for which the thursday
@ -49,6 +59,7 @@ extern "C" {
* part of week 1 of the next year.
*/
- (NSInteger) weekOfYear;
@end
#endif /* OS_API_VERSION */

View file

@ -31,16 +31,23 @@
*/
@implementation NSCalendarDate (GNUstepBase)
/**
* The ISO standard week of the year is based on the first week of the
* year being that week (starting on monday) for which the thursday
* is on or after the first of january.<br />
* This has the effect that, if january first is a friday, saturday or
* sunday, the days of that week (up to and including the sunday) are
* considered to be in week 53 of the preceding year. Similarly if the
* last day of the year is a monday tuesday or wednesday, these days are
* part of week 1 of the next year.
*/
- (NSUInteger) isoYear
{
NSUInteger year = [self yearOfCommonEra];
NSUInteger week = [self weekOfYear];
NSUInteger month = [self monthOfYear];
if (week == 1 && month == 12)
{
year++;
}
else if (week >= 52 && month == 1)
{
year--;
}
return year;
}
- (NSInteger) weekOfYear
{
NSInteger dayOfWeek = [self dayOfWeek];