[haiku-commits] r35894 - in haiku/trunk: headers/os/support src/kits/support

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 17 Mar 2010 19:51:41 +0100 (CET)

Author: stippi
Date: 2010-03-17 19:51:41 +0100 (Wed, 17 Mar 2010)
New Revision: 35894
Changeset: http://dev.haiku-os.org/changeset/35894/haiku

Modified:
   haiku/trunk/headers/os/support/DateTime.h
   haiku/trunk/src/kits/support/DateTime.cpp
Log:
 * Added copy constructors.
 * Let the AddHours(), Add*() return itself, so that they can be chained.
 * Made the previous *Name() methods static and added non-static versions that
   take the day/month of the object.
 * Make BDateTime::Date/Time() return references (const or non-const).
 * Fixed the BDateTime comparison operators.


Modified: haiku/trunk/headers/os/support/DateTime.h
===================================================================
--- haiku/trunk/headers/os/support/DateTime.h   2010-03-17 15:39:28 UTC (rev 
35893)
+++ haiku/trunk/headers/os/support/DateTime.h   2010-03-17 18:51:41 UTC (rev 
35894)
@@ -33,6 +33,7 @@
 class BTime {
 public:
                                                                BTime();
+                                                               BTime(const 
BTime& other);
                                                                BTime(int32 
hour, int32 minute, int32 second,
                                                                        int32 
microsecond = 0);
                                                                BTime(const 
BMessage* archive);
@@ -52,11 +53,11 @@
                        bool                            SetTime(int32 hour, 
int32 minute, int32 second,
                                                                        int32 
microsecond = 0);
 
-                       void                            AddHours(int32 hours);
-                       void                            AddMinutes(int32 
minutes);
-                       void                            AddSeconds(int32 
seconds);
-                       void                            AddMilliseconds(int32 
milliseconds);
-                       void                            AddMicroseconds(int32 
microseconds);
+                       BTime&                          AddHours(int32 hours);
+                       BTime&                          AddMinutes(int32 
minutes);
+                       BTime&                          AddSeconds(int32 
seconds);
+                       BTime&                          AddMilliseconds(int32 
milliseconds);
+                       BTime&                          AddMicroseconds(int32 
microseconds);
 
                        int32                           Hour() const;
                        int32                           Minute() const;
@@ -77,7 +78,7 @@
 
 private:
                        bigtime_t                       _Microseconds() const;
-                       void                            
_AddMicroseconds(bigtime_t microseconds);
+                       BTime&                          
_AddMicroseconds(bigtime_t microseconds);
                        bool                            _SetTime(bigtime_t 
hour, bigtime_t minute,
                                                                        
bigtime_t second, bigtime_t microsecond);
 
@@ -89,6 +90,7 @@
 class BDate {
 public:
                                                                BDate();
+                                                               BDate(const 
BDate& other);
                                                                BDate(int32 
year, int32 month, int32 day);
                                                                BDate(const 
BMessage* archive);
                                                                ~BDate();
@@ -126,12 +128,18 @@
                        int32                           DaysInYear() const;
                        int32                           DaysInMonth() const;
 
-                       BString                         ShortDayName(int32 day) 
const;
-                       BString                         ShortMonthName(int32 
month) const;
+                       BString                         ShortDayName() const;
+       static  BString                         ShortDayName(int32 day);
 
-                       BString                         LongDayName(int32 day) 
const;
-                       BString                         LongMonthName(int32 
month) const;
+                       BString                         ShortMonthName() const;
+       static  BString                         ShortMonthName(int32 month);
 
+                       BString                         LongDayName() const;
+       static  BString                         LongDayName(int32 day);
+
+                       BString                         LongMonthName() const;
+       static  BString                         LongMonthName(int32 month);
+
                        int32                           DateToJulianDay() const;
        static  BDate                           JulianDayToDate(int32 
julianDay);
 
@@ -171,10 +179,12 @@
        static  BDateTime                       CurrentDateTime(time_type type);
                        void                            SetDateTime(const BDate 
&date, const BTime &time);
 
-                       BDate                           Date() const;
+                       BDate&                          Date();
+                       const BDate&            Date() const;
                        void                            SetDate(const BDate 
&date);
 
-                       BTime                           Time() const;
+                       BTime&                          Time();
+                       const BTime&            Time() const;
                        void                            SetTime(const BTime 
&time);
 
                        int32                           Time_t() const;

Modified: haiku/trunk/src/kits/support/DateTime.cpp
===================================================================
--- haiku/trunk/src/kits/support/DateTime.cpp   2010-03-17 15:39:28 UTC (rev 
35893)
+++ haiku/trunk/src/kits/support/DateTime.cpp   2010-03-17 18:51:41 UTC (rev 
35894)
@@ -38,12 +38,23 @@
        but be aware IsValid() will return false.
 */
 BTime::BTime()
-       : fMicroseconds(-1)
+       :
+       fMicroseconds(-1)
 {
 }
 
 
 /*!
+       Constructs a new BTime object as a copy of \c other.
+*/
+BTime::BTime(const BTime& other)
+       :
+       fMicroseconds(other.fMicroseconds)
+{
+}
+
+
+/*!
        Constructs a BTime object with \c hour \c minute, \c second, \c 
microsecond.
 
        \c hour must be between 0 and 23, \c minute and \c second must be 
between
@@ -51,7 +62,8 @@
        specified time is invalid, the time is not set and IsValid() returns 
false.
 */
 BTime::BTime(int32 hour, int32 minute, int32 second, int32 microsecond)
-       : fMicroseconds(-1)
+       :
+       fMicroseconds(-1)
 {
        _SetTime(hour, minute, second, microsecond);
 }
@@ -61,7 +73,8 @@
        Constructs a new BTime object from the provided BMessage archive.
 */
 BTime::BTime(const BMessage* archive)
-       : fMicroseconds(-1)
+       :
+       fMicroseconds(-1)
 {
        if (archive == NULL)
                return;
@@ -192,10 +205,11 @@
        Adds \c hours to the current time. If the passed value is negativ it 
will
        become earlier. Note: The time will wrap if it passes midnight.
 */
-void
+BTime&
 BTime::AddHours(int32 hours)
 {
-       _AddMicroseconds(bigtime_t(hours % kHoursPerDay) * 
kMicrosecondsPerHour);
+       return _AddMicroseconds(bigtime_t(hours % kHoursPerDay)
+               * kMicrosecondsPerHour);
 }
 
 
@@ -203,11 +217,11 @@
        Adds \c minutes to the current time. If the passed value is negativ it 
will
        become earlier. Note: The time will wrap if it passes midnight.
 */
-void
+BTime&
 BTime::AddMinutes(int32 minutes)
 {
-       _AddMicroseconds(bigtime_t(minutes % kMinutesPerDay) *
-               kMicrosecondsPerMinute);
+       return _AddMicroseconds(bigtime_t(minutes % kMinutesPerDay)
+               * kMicrosecondsPerMinute);
 }
 
 
@@ -215,11 +229,11 @@
        Adds \c seconds to the current time. If the passed value is negativ it 
will
        become earlier. Note: The time will wrap if it passes midnight.
 */
-void
+BTime&
 BTime::AddSeconds(int32 seconds)
 {
-       _AddMicroseconds(bigtime_t(seconds % kSecondsPerDay) *
-               kMicrosecondsPerSecond);
+       return _AddMicroseconds(bigtime_t(seconds % kSecondsPerDay)
+               * kMicrosecondsPerSecond);
 }
 
 
@@ -227,10 +241,11 @@
        Adds \c milliseconds to the current time. If the passed value is 
negativ it
        will become earlier. Note: The time will wrap if it passes midnight.
 */
-void
+BTime&
 BTime::AddMilliseconds(int32 milliseconds)
 {
-       _AddMicroseconds(bigtime_t(milliseconds % kMillisecondsPerDay) * 1000);
+       return _AddMicroseconds(bigtime_t(milliseconds % kMillisecondsPerDay)
+               * 1000);
 }
 
 
@@ -238,10 +253,10 @@
        Adds \c microseconds to the current time. If the passed value is 
negativ it
        will become earlier. Note: The time will wrap if it passes midnight.
 */
-void
+BTime&
 BTime::AddMicroseconds(int32 microseconds)
 {
-       _AddMicroseconds(microseconds);
+       return _AddMicroseconds(microseconds);
 }
 
 
@@ -396,7 +411,7 @@
 }
 
 
-void
+BTime&
 BTime::_AddMicroseconds(bigtime_t microseconds)
 {
        bigtime_t count = 0;
@@ -405,6 +420,7 @@
                        kMicrosecondsPerDay;
        }
        fMicroseconds = (_Microseconds() + microseconds + count) % 
kMicrosecondsPerDay;
+       return *this;
 }
 
 
@@ -432,14 +448,27 @@
        Constructs a new BDate object. IsValid() will return false.
 */
 BDate::BDate()
-       : fDay(-1),
-         fYear(0),
-         fMonth(-1)
+       :
+       fDay(-1),
+       fYear(0),
+       fMonth(-1)
 {
 }
 
 
 /*!
+       Constructs a new BDate object as a copy of \c other.
+*/
+BDate::BDate(const BDate& other)
+       :
+       fDay(other.fDay),
+       fYear(other.fYear),
+       fMonth(other.fMonth)
+{
+}
+
+
+/*!
        Constructs a BDate object with \c year \c month and \c day.
 
        Please note that a date before 1.1.4713 BC, a date with year 0 and a 
date
@@ -458,9 +487,10 @@
        Constructs a new BDate object from the provided archive.
 */
 BDate::BDate(const BMessage* archive)
-       : fDay(-1),
-         fYear(0),
-         fMonth(-1)
+       :
+       fDay(-1),
+       fYear(0),
+       fMonth(-1)
 {
        if (archive == NULL)
                return;
@@ -864,12 +894,22 @@
 
 
 /*!
+       Returns the short day name of this object.
+*/
+BString
+BDate::ShortDayName() const
+{
+       return ShortDayName(DayOfWeek());
+}
+
+
+/*!
        Returns the short day name in case of an valid day, otherwise an empty
        string. The passed \c day must be in the range of 1 to 7 while 1 stands 
for
        monday.
 */
-BString
-BDate::ShortDayName(int32 day) const
+/*static*/ BString
+BDate::ShortDayName(int32 day)
 {
        if (day < 1 || day > 7)
                return BString();
@@ -886,11 +926,21 @@
 
 
 /*!
+       Returns the short month name of this object.
+*/
+BString
+BDate::ShortMonthName() const
+{
+       return ShortMonthName(Month());
+}
+
+
+/*!
        Returns the short month name in case of an valid month, otherwise an 
empty
        string. The passed \c month must be in the range of 1 to 12.
 */
-BString
-BDate::ShortMonthName(int32 month) const
+/*static*/ BString
+BDate::ShortMonthName(int32 month)
 {
        if (month < 1 || month > 12)
                return BString();
@@ -907,12 +957,22 @@
 
 
 /*!
+       Returns the long day name of this object's week day.
+*/
+BString
+BDate::LongDayName() const
+{
+       return LongDayName(DayOfWeek());
+}
+
+
+/*!
        Returns the long day name in case of an valid day, otherwise an empty
        string. The passed \c day must be in the range of 1 to 7 while 1 stands 
for
        monday.
 */
-BString
-BDate::LongDayName(int32 day) const
+/*static*/ BString
+BDate::LongDayName(int32 day)
 {
        if (day < 1 || day > 7)
                return BString();
@@ -929,11 +989,21 @@
 
 
 /*!
+       Returns the long month name of this object's month.
+*/
+BString
+BDate::LongMonthName() const
+{
+       return LongMonthName(Month());
+}
+
+
+/*!
        Returns the long month name in case of an valid month, otherwise an 
empty
        string. The passed \c month must be in the range of 1 to 12.
 */
-BString
-BDate::LongMonthName(int32 month) const
+/*static*/ BString
+BDate::LongMonthName(int32 month)
 {
        if (month < 1 || month > 12)
                return BString();
@@ -1218,7 +1288,17 @@
 /*!
        Returns the current date of this object.
 */
-BDate
+BDate&
+BDateTime::Date()
+{
+       return fDate;
+}
+
+
+/*!
+       Returns the current date of this object.
+*/
+const BDate&
 BDateTime::Date() const
 {
        return fDate;
@@ -1238,7 +1318,17 @@
 /*!
        Returns the current time of this object.
 */
-BTime
+BTime&
+BDateTime::Time()
+{
+       return fTime;
+}
+
+
+/*!
+       Returns the current time of this object.
+*/
+const BTime&
 BDateTime::Time() const
 {
        return fTime;
@@ -1328,7 +1418,11 @@
 bool
 BDateTime::operator<(const BDateTime& dateTime) const
 {
-       return fTime < dateTime.fTime && fDate < dateTime.fDate;
+       if (fDate < dateTime.fDate)
+               return true;
+       if (fDate == dateTime.fDate)
+               return fTime < dateTime.fTime;
+       return false;
 }
 
 
@@ -1339,7 +1433,11 @@
 bool
 BDateTime::operator<=(const BDateTime& dateTime) const
 {
-       return fTime <= dateTime.fTime && fDate <= dateTime.fDate;
+       if (fDate < dateTime.fDate)
+               return true;
+       if (fDate == dateTime.fDate)
+               return fTime <= dateTime.fTime;
+       return false;
 }
 
 
@@ -1349,7 +1447,11 @@
 bool
 BDateTime::operator>(const BDateTime& dateTime) const
 {
-       return fTime > dateTime.fTime && fDate > dateTime.fDate;
+       if (fDate > dateTime.fDate)
+               return true;
+       if (fDate == dateTime.fDate)
+               return fTime > dateTime.fTime;
+       return false;
 }
 
 
@@ -1360,7 +1462,11 @@
 bool
 BDateTime::operator>=(const BDateTime& dateTime) const
 {
-       return fTime >= dateTime.fTime && fDate >= dateTime.fDate;
+       if (fDate > dateTime.fDate)
+               return true;
+       if (fDate == dateTime.fDate)
+               return fTime >= dateTime.fTime;
+       return false;
 }
 
 


Other related posts:

  • » [haiku-commits] r35894 - in haiku/trunk: headers/os/support src/kits/support - superstippi