home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Relative Time Strings / Relative Time Strings.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  2.3 KB  |  99 lines  |  [TEXT/KAHL]

  1. #ifndef    __RELTIM__
  2. #define    __RELTIM__
  3.  
  4. //
  5. //    Relative Time Strings.h
  6. //
  7.  
  8. ////////////////////////
  9. //    Constants
  10. ////////////////////////
  11. #define        FOUR_YEAR_SECS    126230400    // 3 * 365 + 366
  12. #define        YEAR_SECS        31536000
  13. #define        LEAP_YEAR_SECS    31622400
  14. #define        WEEK_SECS        604800
  15. #define        DAY_SECS        86400
  16. #define        HOUR_SECS        3600
  17. #define        MINUTE_SECS        60
  18.  
  19. #define        YEAR_PLACES        6        // decimal places when displaying fractional
  20. #define        MONTH_PLACES    5
  21. #define        WEEK_PLACES        4
  22. #define        DAY_PLACES        4
  23. #define        HOUR_PLACES        3
  24. #define        MINUTE_PLACES    2
  25.  
  26. #define        NUMBER_SEPARATOR  '-'
  27.  
  28. /*************** Displaying Types ***************/
  29. enum{    year         = 0x0001,
  30.         month        = 0x0002,
  31.         week         = 0x0004,
  32.         day         = 0x0008,
  33.         hour         = 0x0010,
  34.         minute         = 0x0020,
  35.         second         = 0x0040,
  36.         
  37.         calendarDayMask    = 0x000F,  //use to determine if days should change at midnight
  38.         allMask            = 0x007F
  39.     };
  40. typedef short Display_Items;
  41.  
  42.  
  43. struct Display_Type {
  44.     Display_Items     display_items;
  45.     Display_Items    last_item;
  46.     Boolean            clockDisplayEnable;
  47.     Boolean         fractional;
  48.     Boolean         significant;
  49.     Boolean            count_days;
  50.     Boolean            hide_zeros;
  51.     Boolean            allow_clock_display;
  52.     Boolean            allow_day_rounding;
  53.     Boolean            abbreviated;
  54.     };
  55. typedef struct Display_Type Display_Type;
  56. typedef Display_Type *Display_Type_Ptr;
  57.  
  58.  
  59. struct Display_Elements {
  60.     Boolean            inPast;
  61.     Boolean            clockDisplay;
  62.     Boolean            count_days;
  63.     Display_Items     display_items;
  64.     Display_Items    last_item;
  65.     unsigned long    year;
  66.     unsigned long    month;
  67.     unsigned long    week;
  68.     unsigned long    day;
  69.     unsigned long    hour;
  70.     unsigned long    minute;
  71.     unsigned long    second;
  72.     Str15            fractional;
  73.     };
  74. typedef struct Display_Elements Display_Elements;
  75. typedef Display_Elements *Display_Elements_Ptr;
  76.  
  77.  
  78. /*********************************************
  79. *    structure for keeping everything we need to know about each event.
  80. **********************************************/
  81.  
  82. struct Count_Rec {
  83.     unsigned long    From_In_Secs;
  84.     unsigned long    Target_In_Secs;
  85.     Display_Type    Display;
  86.     };
  87. typedef struct Count_Rec Count_Rec;
  88. typedef Count_Rec *Count_Rec_Ptr;
  89.  
  90.  
  91. ////////////////////////
  92. //    Prototypes
  93. ////////////////////////
  94. void Calculate_Rel_Time_Str (Count_Rec_Ptr count_ptr, Display_Elements_Ptr element_ptr);
  95. void Get_Rel_Time_Str (Count_Rec_Ptr count_ptr, Str255 the_str);
  96. void Assemble_Time_String (Display_Elements_Ptr element_ptr, Str255 the_str, Boolean abrev_string);
  97.  
  98. #endif
  99.