home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / ODate.hpp < prev    next >
C/C++ Source or Header  |  1996-07-20  |  6KB  |  255 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // ODate.hpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31.  
  32. // $Header: E:/Projects/OCL/Include/rcs/O3State.hpp 1.6 1996/01/25 03:46:36 B.STEIN Exp B.STEIN $
  33.  
  34.  
  35. #ifndef ODATE_INCLUDED
  36.   #define ODATE_INCLUDED
  37.  
  38. #include <time.h>
  39.  
  40. typedef class ODate *pODate;
  41.  
  42.  
  43. class __CPP_EXPORT__ ODate
  44.     : public OCLObject
  45. {
  46.  public:
  47.  
  48.    typedef enum
  49.       {
  50.        Monday = 0,
  51.        Tuesday,
  52.        Wednesday,
  53.        Thursday,
  54.        Friday,
  55.        Saturday,
  56.        Sunday
  57.       }
  58.    DayOfWeek;
  59.  
  60.    typedef enum
  61.       {
  62.        January = 1,
  63.        February,
  64.        March,
  65.        April,
  66.        May,
  67.        June,
  68.        July,
  69.        August,
  70.        September,
  71.        October,
  72.        November,
  73.        December
  74.       }
  75.    Month;
  76.  
  77.    typedef enum
  78.       {
  79.  
  80. // earth style date formats
  81.        mm_dd_yy = 0,   // mm. dd. yy
  82.        dd_mm_yy,       // dd. mm. yy
  83.        yy_mm_dd,       // yy  mm. dd.
  84.        mm_dd_yyyy,     // mm. dd. yyyy
  85.        dd_mm_yyyy,     // dd. mm. yyyy
  86.        yyyy_mm_dd,     // yyyy  mm. dd.
  87.  
  88. // stardate date formats
  89.        sd_pi,          // [-31] 7837
  90.        sd_pif1,        // [-31] 7837.5
  91.        sd_pif2,        // [-31] 7837.53
  92.        sd_pif3,        // [-31] 7837.532
  93.        sd_pif4,        // [-31] 7837.5321
  94.        sd_if,          // 7837
  95.        sd_if1,         // 7837.5
  96.        sd_if2,         // 7837.53 
  97.        sd_if3,         // 7837.532
  98.        sd_if4          // 7837.5321
  99.       }
  100.    DateFormat;
  101.  
  102. // imbedded structs and classes
  103.  
  104.    struct MDY
  105.       {
  106.        ODate::Month    month;
  107.        INT             day;
  108.        INT             year;
  109.       };
  110.     
  111.  private:
  112.  
  113.     ULONG       julian;
  114.     tm          _now_tm;
  115.     time_t      _now_time_t;
  116.     LONG        prefix;     // before or after star time
  117.     LONG        integer;    // before comma
  118.     LONG        fraction;   // after comma
  119.  
  120.  protected:
  121.  
  122.     ODate
  123.       &init      (ODate::Month aMonth,
  124.                   INT          aDay,
  125.                   INT          aYear),
  126.       &calculate ();
  127.  
  128.  
  129.  public:
  130.  
  131. // ctors
  132.  
  133.    ODate          ();
  134.  
  135.    ODate          (ODate::Month aMonth,
  136.                    INT          aDay,
  137.                    INT          aYear);
  138.  
  139.    ODate          (INT          aDay,
  140.                    ODate::Month aMonth,
  141.                    INT          aYear);
  142.  
  143.    ODate          (INT   aYear,
  144.                    INT   aDay);
  145.  
  146.    ODate          (const ODate &aDate);
  147.  
  148.    ODate          (ULONG julianDayNumber);
  149.  
  150.    ODate          (const _CDATE &cDate);
  151.  
  152. // dtor
  153.  
  154.    virtual
  155.      ~ODate       ();
  156.  
  157. // utility members
  158.  
  159.   virtual
  160.      PSZ isOfType () const;
  161.  
  162.   static ODate
  163.       today       (),
  164.       now         ();
  165.  
  166.  
  167.   OString
  168.       asString    (DateFormat  dateFmt = dd_mm_yy) const,
  169.       asString    (PCSZ        fmt)                const;
  170.  
  171.   friend ostream
  172.       &operator << (ostream     &aStream,
  173.                     const ODate &aDate);
  174.  
  175.   ODate::DayOfWeek
  176.       dayOfWeek   () const;
  177.  
  178.   OString
  179.       dayName     () const;
  180.  
  181.   INT
  182.       dayOfMonth  () const,
  183.       dayOfYear   () const;
  184.  
  185.   ODate::Month
  186.       monthOfYear () const;
  187.  
  188.   OString
  189.       monthName   () const;
  190.  
  191.   INT
  192.       year        () const;
  193.  
  194.   ULONG
  195.       julianDate  () const;
  196.  
  197.   _CDATE
  198.       asCDATE     () const;
  199.  
  200.   BOOL
  201.       operator == (const ODate &aDate) const,
  202.       operator != (const ODate &aDate) const,
  203.       operator <  (const ODate &aDate) const,
  204.       operator <= (const ODate &aDate) const,
  205.       operator >  (const ODate &aDate) const,
  206.       operator >= (const ODate &aDate) const;
  207.  
  208.  ODate
  209.       operator +  (INT numDays) const,
  210.       operator -  (INT numDays) const;
  211.  
  212.  ODate
  213.      &operator += (INT numDays),
  214.      &operator -= (INT numDays);
  215.  
  216.  LONG
  217.       operator -  (const ODate &aDate) const;
  218.  
  219.  static OString
  220.       dayName     (ODate::DayOfWeek aDay),
  221.       monthName   (ODate::Month     aMonth);
  222.  
  223.  static INT
  224.     daysInMonth   (Month aMonth,
  225.                    INT   aYear),
  226.     daysInYear    (INT   aYear);
  227.  
  228.  static BOOL
  229.     isLeapYear    (INT   aYear),
  230.     isValid       (Month aMonth,
  231.                    INT   aDay,
  232.                    INT   aYear),
  233.     isValid       (INT   aDay,
  234.                    Month aMonth,
  235.                    INT   aYear),
  236.     isValid       (INT   aYear,
  237.                    INT   aDay);
  238.  
  239.  static ODate::MDY
  240.     julianToMDY   (ULONG julianDate),
  241.     DYToMDY       (INT aDay, INT aYear);
  242.  
  243.  static unsigned long
  244.     MDYToJulian   (ODate::MDY aMDY);
  245.  
  246. };
  247.  
  248.  
  249.  
  250.  
  251. #endif // ODATE_INCLUDED
  252.  
  253. // end of source
  254.  
  255.