From: znek Date: Wed, 9 Feb 2005 13:51:13 +0000 (+0000) Subject: julianNumber <-> date conversion X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe7bc6d5486e1d318377f8bedb5598f1dca67b93;p=sope julianNumber <-> date conversion git-svn-id: http://svn.opengroupware.org/SOPE/trunk@548 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOControl/EOControl.xcode/project.pbxproj b/sope-core/EOControl/EOControl.xcode/project.pbxproj index 78f2f8ab..8bc23ac4 100644 --- a/sope-core/EOControl/EOControl.xcode/project.pbxproj +++ b/sope-core/EOControl/EOControl.xcode/project.pbxproj @@ -159,7 +159,7 @@ ); buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.49; + DYLIB_CURRENT_VERSION = 4.5.50; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = common.h; diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 862a630a..fa1cd364 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,8 @@ +2005-02-09 Marcus Mueller + + * FdExt.subproj/NSCalendarDate+misc.m: Julian number <-> date + conversion methods (v4.5.144) + 2005-02-09 Helge Hess * FdExt.subproj/NSString+misc.m: do not quote the last newline if the diff --git a/sope-core/NGExtensions/FdExt.subproj/NSCalendarDate+misc.m b/sope-core/NGExtensions/FdExt.subproj/NSCalendarDate+misc.m index d13b07de..edfb1822 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSCalendarDate+misc.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSCalendarDate+misc.m @@ -505,6 +505,72 @@ } #endif +/* Oct. 15, 1582 */ +#define IGREG (15+31L*(10+12L*1582)) + +- (long)julianNumber { + long jul; + int ja, jy, jm, year, month, day; + + year = [self yearOfCommonEra]; + month = [self monthOfYear]; + day = [self dayOfMonth]; + jy = year; + + if (jy == 0) + return 0; + if (jy < 0) + jy++; + + if (month > 2) + jm = month + 1; + else { + jy--; + jm = month + 13; + } + + jul = (long) (floor(365.25 * jy) + floor(30.6001 * jm) + day + 1720995); + + if (day + 31L * (month + 12L * year) >= IGREG) { + ja = (int)(0.01 * jy); + jul += 2 - ja + (int) (0.25 * ja); + } + return jul; +} + ++ (NSCalendarDate *)dateForJulianNumber:(long)_jn { + long ja, jalpha, jb, jc, jd, je; + unsigned day, month, year; + + if (_jn >= IGREG) { + jalpha = (long)(((float) (_jn - 1867216) - 0.25) / 36524.25); + ja = _jn + 1 + jalpha - (long)(0.25 * jalpha); + } else { + ja = _jn; + } + + jb = ja + 1524; + jc = (long)(6680.0 + ((float)(jb - 2439870) - 122.1) / 365.25); + jd = (long)(365 * jc + (0.25 * jc)); + je = (long)((jb - jd) / 30.6001); + day = jb - jd - (long)(30.6001 * je); + month = je - 1; + if (month > 12) + month -= 12; + year = jc - 4715; + if (month > 2) + year--; + if (year <= 0) + year--; + return [NSCalendarDate dateWithYear:year + month:month + day:day + hour:12 + minute:0 + second:0 + timeZone:nil]; +} + @end /* NSCalendarDate(misc) */ /* static linking */ diff --git a/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj b/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj index c14514a4..a3c0c363 100644 --- a/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj +++ b/sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj @@ -1715,7 +1715,7 @@ ); buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.140; + DYLIB_CURRENT_VERSION = 4.5.144; FRAMEWORK_SEARCH_PATHS = "$(LOCAL_LIBRARY_DIR)/Frameworks"; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; diff --git a/sope-core/NGExtensions/NGExtensions/NSCalendarDate+misc.h b/sope-core/NGExtensions/NGExtensions/NSCalendarDate+misc.h index a899f3e8..28d10fd3 100644 --- a/sope-core/NGExtensions/NGExtensions/NSCalendarDate+misc.h +++ b/sope-core/NGExtensions/NGExtensions/NSCalendarDate+misc.h @@ -40,6 +40,9 @@ timeZone:(NSTimeZone *)_tz; - (NSCalendarDate *)mondayOfWeek:(int)_weekNumber; ++ (NSCalendarDate *)dateForJulianNumber:(long)_jn; +- (long)julianNumber; + - (NSCalendarDate *)firstDayOfMonth; - (NSCalendarDate *)lastDayOfMonth; - (NSCalendarDate *)mondayOfWeek; diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 5bbbefc9..2451bb22 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=143 +SUBMINOR_VERSION:=144 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39