]> err.no Git - sope/commitdiff
julianNumber <-> date conversion
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 9 Feb 2005 13:51:13 +0000 (13:51 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 9 Feb 2005 13:51:13 +0000 (13:51 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@548 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-core/EOControl/EOControl.xcode/project.pbxproj
sope-core/NGExtensions/ChangeLog
sope-core/NGExtensions/FdExt.subproj/NSCalendarDate+misc.m
sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj
sope-core/NGExtensions/NGExtensions/NSCalendarDate+misc.h
sope-core/NGExtensions/Version

index 78f2f8ab648ec5501668ef2ee0187591be394e67..8bc23ac4fb26c356ed3adb7f0928e765ceb44990 100644 (file)
                        );
                        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;
index 862a630a7e61a060c85494d6fa7bc3a26e306240..fa1cd364b942518bcaea89473edbdf0462663683 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-09  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * FdExt.subproj/NSCalendarDate+misc.m: Julian number <-> date
+         conversion methods (v4.5.144)
+
 2005-02-09  Helge Hess  <helge.hess@opengroupware.org>
 
        * FdExt.subproj/NSString+misc.m: do not quote the last newline if the
index d13b07debc1081f5841790b09d659e22c3d6f140..edfb18226a47487113ada1194faa8cea6d5a3c96 100644 (file)
 }
 #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 */
index c14514a4f8ef49d8f45d8a12d8d6c2ccead1a11d..a3c0c363ae1e7d740d22b6b996355566275019ec 100644 (file)
                        );
                        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;
index a899f3e8ef723fb9adad8a79da72804740cb80f3..28d10fd35c52d22d6e8ea7dd969b2658d569e232 100644 (file)
@@ -40,6 +40,9 @@
   timeZone:(NSTimeZone *)_tz;
 - (NSCalendarDate *)mondayOfWeek:(int)_weekNumber;
 
++ (NSCalendarDate *)dateForJulianNumber:(long)_jn;
+- (long)julianNumber;
+
 - (NSCalendarDate *)firstDayOfMonth;
 - (NSCalendarDate *)lastDayOfMonth;
 - (NSCalendarDate *)mondayOfWeek;
index 5bbbefc93b9fb357f183b2540ce635396c091361..2451bb22bdca0e9b0c33ca39c7d2f2e4feaad876 100644 (file)
@@ -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