Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

time.Date.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 Eric NICOLAS
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018   --------------------------------------------------------------------------*/
00019 #ifndef _SWORD_TIME_DATE_
00020 #define _SWORD_TIME_DATE_
00021 
00022 #include "sword/time.Time.h"
00023 #include "sword/time.CalendarWestern.h"
00024 #include "sword/time.CalendarGregorian.h"
00025 
00026 namespace sword {
00027 
00029         class SWORDDECL Date : public Comparable<Date> {
00030         public:
00032                 Date() throw();
00033 
00035                 Date(const Date &rhs) throw();
00036 
00038                 Date &operator=(const Date &rhs) throw();
00039 
00041                 Date(word day, word month, word year, word hour, word minute, word second, word millis, const Calendar &calendar) throw();
00042 
00044 
00045                 Date(word day, word month, word year, word hour, word minute, word second, word millis) throw();
00046 
00048 
00050                 Date(word day, word month, word year, const Calendar &calendar) throw();
00051 
00053 
00056                 Date(word day, word month, word year) throw();
00057 
00059                 Date(Time time, const Calendar &calendar);
00060 
00062 
00064                 Date(Time time);
00065 
00067                 Date(int packed, const Calendar &calendar);
00068 
00070 
00072                 Date(int packed);
00073 
00075 
00077                 static Date now(const Calendar &calendar);
00078 
00080 
00083                 static Date now();
00084 
00086 
00088                 static Date nowUTC(const Calendar &calendar);
00089 
00091 
00094                 static Date nowUTC();
00095 
00096                 // --- Read Accessors
00097 
00099                 word day() const throw();
00100 
00102                 word month() const throw();
00103 
00105                 word year() const throw();
00106 
00108                 word hour() const throw();
00109 
00111                 word minute() const throw();
00112 
00114                 word second() const throw();
00115 
00117                 word millis() const throw();
00118 
00120                 const Calendar& calendar() const throw();
00121 
00122                 // --- Other Accessors (computed data)
00123 
00125 
00128                 word weekDay() const;
00129 
00131                 word weekNumber() const;
00132 
00134                 word dayWithinYear() const;
00135 
00136                 // --- Write Accessors
00137 
00139                 void day(word value) throw();
00140 
00142                 void month(word value) throw();
00143 
00145                 void year(word value) throw();
00146 
00148                 void hour(word value) throw();
00149 
00151                 void minute(word value) throw();
00152 
00154                 void second(word value) throw();
00155 
00157                 void millis(word value) throw();
00158 
00159                 // --- Other access
00160 
00162                 bool empty() const throw();
00163 
00165                 void clear() throw();
00166 
00168                 void set(word day, word month, word year, word hour, word minute, word second, word millis, const Calendar &calendar) throw();
00169 
00171                 void set(word day, word month, word year, const Calendar &calendar) throw();
00172 
00173                 // --- Simple date arithmetic
00174 
00176 
00183                 void addYears(int years, bool endToEnd = false);
00184 
00186 
00191                 void addMonths(int months, bool endToEnd = false);
00192 
00194                 void addDays(int days);
00195 
00197                 void addHours(int hours);
00198 
00200                 void addMinutes(int minutes);
00201 
00203                 void addSeconds(int seconds);
00204 
00206                 void addMillis(int millis);
00207 
00209                 void next();
00210 
00212                 void prev();
00213 
00214                 // --- Time conversion
00215 
00217                 void fromTime(Time time, const Calendar &calendar);
00218 
00220 
00222                 void fromTime(Time time);
00223 
00225                 Time toTime() const;
00226 
00228     void fromPackedDate(int packed, const Calendar &calendar);
00229 
00231                 void fromPackedDate(int packed);
00232 
00234                 int toPackedDate() const;
00235 
00237                 bool valid() const;
00238 
00239                 // --- Input / Output
00240 
00242 
00270                 std::string toString(const std::string &format) const;
00271 
00273 
00277                 void fromString(const std::string &format, const std::string &data);
00278 
00279                 // Standard formats
00280                 static const char *formatRFC822UTC;
00281                 static const char *formatRFC822;
00282 
00284                 static int compare(const Date &lhs, const Date &rhs);
00285 
00286                 // --- Exception
00287 
00288                 class FormatException : public Exception {};
00289     class RangeException  : public Exception {};
00290 
00291         private:
00292                 word  day_;       // The day of the month (1-based)
00293                 word  month_;     // The month (1-based)
00294                 word  year_;      // The year (absolute)
00295                 word  hour_;      // The hour (0-based)
00296                 word  minute_;    // The minutes (0-based)
00297                 word  second_;    // The seconds (0-based)
00298                 word  millis_;    // The milliseconds (0-based)
00299                 Calendar &calendar_;  // The calendar used for all conversions
00300 
00301                 // computes a pseudo-serial number for this date (unique hash value,
00302                 // which is ordered just like the date is)
00303                 int64 pseudoSerial_() const;
00304         };
00305 
00306 } // namespace sword
00307 
00308 #include "sword.private/time.Date.inl"
00309 
00310 #endif // _SWORD_TIME_DATE_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2