home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / unixlib / src / timeconvert.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  95 lines

  1. #include "amiga.h"
  2. #include "timeconvert.h"
  3. #include <time.h>
  4. #include <proto/timer.h>
  5.  
  6. int _gettime(struct timeval *tp)
  7. {
  8.   struct tm *local;
  9.   time_t gmt;
  10.  
  11.   GetSysTime(tp);
  12.   /* Correct for different epoch (78 vs 70) */
  13.   tp->tv_secs += 252460800;    
  14.  
  15. #ifdef USE_LOCAL
  16.   /* correct for timezone */
  17.   local = gmtime(&tp->tv_secs);
  18.   local->tm_isdst = -1;        /* We don't know about dst */
  19.   gmt = mktime(local);
  20.  
  21.   if (gmt == -1)
  22.     {
  23.       errno = EINVAL;
  24.       return -1;
  25.     }
  26.   tp->tv_secs = gmt;
  27. #endif
  28.   return 0;
  29. }
  30.  
  31. #ifdef USE_LOCAL
  32.  
  33. /* System is storing local time */
  34.  
  35. void _gmt2amiga(time_t time, struct DateStamp *date)
  36. {
  37.   struct tm *local, *gmt;
  38.  
  39.   local = localtime(&time);
  40.   gmt = gmtime(&time);
  41.   date->ds_Tick = 50 * local->tm_sec;
  42.   date->ds_Minute = local->tm_min + local->tm_hour * 60;
  43.  
  44.   /* Now calculate the day assuming we are in GMT */
  45.   date->ds_Days = (time - 252460800) / 86400;
  46.   /* And correct by comparing local with GMT */
  47.   if (local->tm_year < gmt->tm_year ||
  48.       local->tm_year == gmt->tm_year && local->tm_yday < gmt->tm_yday)
  49.     date->ds_Days--;
  50.   if (local->tm_year > gmt->tm_year ||
  51.       local->tm_year == gmt->tm_year && local->tm_yday > gmt->tm_yday)
  52.     date->ds_Days++;
  53. }
  54.  
  55. time_t _amiga2gmt(struct DateStamp *date)
  56. {
  57.   struct tm *local;
  58.   time_t secs;
  59.  
  60.   secs = date->ds_Tick / 50 + date->ds_Minute * 60 + date->ds_Days * 86400 +
  61.     252460800;
  62.   local = gmtime(&secs);
  63.   local->tm_isdst = -1;        /* We don't know about dst */
  64.  
  65.   return mktime(local);
  66. }
  67.  
  68. #else
  69.  
  70. /* System is storing GMT */
  71. /* Leap seconds are not handled !! */
  72.  
  73. void _gmt2amiga(time_t time, struct DateStamp *date)
  74. {
  75.   time_t time78, day_secs;
  76.  
  77.   time78 = time - 252460800;    /* Change Epoch */
  78.   date->ds_Days = time78 / 86400;
  79.   day_secs = time78 % 86400;
  80.   date->ds_Minute = day_secs / 60;
  81.   date->ds_Tick = 50 * (day_secs % 60);
  82. }
  83.  
  84. time_t _amiga2gmt(struct DateStamp *date)
  85. {
  86.   time_t secs;
  87.  
  88.   secs = date->ds_Tick / 50 + date->ds_Minute * 60 + date->ds_Days * 86400 +
  89.     252460800;
  90.  
  91.   return secs;
  92. }
  93.  
  94. #endif
  95.