@@ -35,6 +35,7 @@ class Date
3535 typedef uint8_t day_of_week_type;
3636 typedef uint8_t month_type;
3737 typedef uint16_t year_type;
38+ typedef uint32_t serialize_type;
3839
3940// Constants.
4041public:
@@ -88,17 +89,17 @@ class Date
8889
8990// Static member functions.
9091public:
91- // / Convert date to a 32-bit value that can be ordered.
92- static uint32_t GetDate (day_type day, month_type month, year_type year) throw()
92+ // / Convert date to a 32-bit value that can be ordered and stored .
93+ static serialize_type Serialize (day_type day, month_type month, year_type year) throw()
9394 {
9495 uint32_t date = day;
9596 date |= static_cast <uint32_t >(month) << 8U ;
9697 date |= static_cast <uint32_t >(year) << 16U ;
9798 return date;
9899 }
99100
100- // / Convert a 32-bit ordered value to a day, month and year.
101- static void SetDate ( uint32_t date, day_type& day, month_type& month, year_type& year) throw()
101+ // / Convert a 32-bit ordered or stored value into a day, month and year.
102+ static void Deserialize (serialize_type date, day_type& day, month_type& month, year_type& year) throw()
102103 {
103104 day = static_cast <day_type>(date);
104105 month = static_cast <month_type>(date >> 8U );
@@ -406,7 +407,7 @@ class Date
406407 // / If the user doesn't want to include the current year,
407408 // / then start from the 1st of January of the current year.
408409 // / Note that year will be updated to be the year before the counted days.
409- // / The days returned will be the number of days up to the 1st of January ,
410+ // / The days returned will be the number of days up to the 31st of December ,
410411 // / where there were not enough days remaining to complete a full year.
411412 static size_type SubtractDaysForYears (size_type days,
412413 day_type& day,
@@ -458,14 +459,14 @@ class Date
458459 days -= day;
459460 SetToPreviousMonth (month, year);
460461 size_type days_in_month = GetDaysInMonth (month, year);
461- day = days_in_month;
462+ day = static_cast <day_type>( days_in_month) ;
462463 while (days >= days_in_month)
463464 {
464465 SetToPreviousMonth (month, year);
465466 days -= days_in_month;
466467 total_days += days_in_month;
467468 days_in_month = GetDaysInMonth (month, year);
468- day = days_in_month;
469+ day = static_cast <day_type>( days_in_month) ;
469470 }
470471 }
471472 else
@@ -541,7 +542,7 @@ class Date
541542 // / Create Date object from an unsigned 32-bit value.
542543 Date (uint32_t date) throw ()
543544 {
544- SetDate (date, m_day, m_month, m_year);
545+ Deserialize (date, m_day, m_month, m_year);
545546 }
546547
547548 Date (Date const & date) throw ()
@@ -555,38 +556,38 @@ class Date
555556public:
556557 Date& operator =(Date const & date) throw ()
557558 {
558- SetDate (date);
559+ Copy (date);
559560 return *this ;
560561 }
561562
562563 bool operator <(Date const & other) const throw ()
563564 {
564- return GetDate () < other.GetDate ();
565+ return Serialize () < other.Serialize ();
565566 }
566567
567568 bool operator <=(Date const & other) const throw ()
568569 {
569- return GetDate () <= other.GetDate ();
570+ return Serialize () <= other.Serialize ();
570571 }
571572
572573 bool operator >(Date const & other) const throw ()
573574 {
574- return GetDate () > other.GetDate ();
575+ return Serialize () > other.Serialize ();
575576 }
576577
577578 bool operator >=(Date const & other) const throw ()
578579 {
579- return GetDate () >= other.GetDate ();
580+ return Serialize () >= other.Serialize ();
580581 }
581582
582583 bool operator ==(Date const & other) const throw ()
583584 {
584- return GetDate () == other.GetDate ();
585+ return Serialize () == other.Serialize ();
585586 }
586587
587588 bool operator !=(Date const & other) const throw ()
588589 {
589- return GetDate () != other.GetDate ();
590+ return Serialize () != other.Serialize ();
590591 }
591592
592593 Date& operator +=(size_type days_to_add) throw ()
@@ -763,18 +764,18 @@ class Date
763764 }
764765
765766 // / Get the date as a 32-bit value for conveniently serializing the date.
766- uint32_t GetDate () const throw()
767+ serialize_type Serialize () const throw()
767768 {
768- return GetDate (m_day, m_month, m_year);
769+ return Serialize (m_day, m_month, m_year);
769770 }
770771
771772 // / Set the date from a 32-bit value for conveniently serializing the date.
772- void SetDate ( uint32_t date) throw()
773+ void Deserialize (serialize_type date) throw()
773774 {
774- SetDate (date, m_day, m_month, m_year);
775+ Deserialize (date, m_day, m_month, m_year);
775776 }
776777
777- void SetDate (Date const & date) throw()
778+ void Copy (Date const & date) throw()
778779 {
779780 m_day = date.m_day ;
780781 m_month = date.m_month ;
@@ -885,7 +886,8 @@ class Date
885886 days -= SubtractDaysForYears (days, day, month, year);
886887 // Remove days to start of month and days for whole previous month.
887888 days -= SubtractDaysForMonths (days, day, month, year);
888- day_type days_in_month = GetDaysInMonth (month, year);
889+ // Day will be at last day of the month, so if day is greater than
890+ // days remaining, day - days will take you correct day for the month.
889891 if (day > days)
890892 day = static_cast <day_type>(day - days);
891893 SetDate (day, month, year);
@@ -907,8 +909,8 @@ class Date
907909
908910 int Compare (Date const & date) const throw()
909911 {
910- uint32_t d1 = GetDate ();
911- uint32_t d2 = date.GetDate ();
912+ uint32_t d1 = Serialize ();
913+ uint32_t d2 = date.Serialize ();
912914 return d1 > d2 ? 1 : (d1 < d2 ? -1 : 0 );
913915 }
914916
0 commit comments