Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  

datetime.h

00001 /***************************************************************************
00002     copyright            : (C) 2002-2005 by Stefano Barbato
00003     email                : [email protected]
00004 
00005     $Id: datetime_8h-source.html,v 1.4 2006-03-12 12:28:31 tat Exp $
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _MIMETIC_RFC822_DATETIME_H
00017 #define _MIMETIC_RFC822_DATETIME_H
00018 #include <string>
00019 #include <iostream>
00020 #include <mimetic/strutils.h>
00021 #include <mimetic/rfc822/fieldvalue.h>
00022 
00023 namespace mimetic
00024 {
00025 
00026 
00027 /// RFC822 DateTime field representation
00028 struct DateTime: public FieldValue
00029 {
00030     struct DayOfWeek {
00031         enum DayName { mnShort = 0, mnLong = 1 };
00032         DayOfWeek(int iDayOfWeek);
00033         DayOfWeek(const std::string&);
00034         bool operator==(const std::string&);
00035         bool operator==(int iDayOfWeek);
00036         std::string name(bool longName = false) const;
00037         short ordinal() const;
00038     private:
00039         static const char *ms_label[][2];
00040         short m_iDayOfWeek;
00041     };
00042     struct Month {
00043         enum MonthName { mnShort = 0, mnLong = 1 };
00044         Month(int iMonth);
00045         Month(const std::string& );
00046         bool operator==(const std::string& ) const;
00047         bool operator==(int iMonth) const;
00048         std::string name(bool longName = false) const;
00049         short ordinal() const;
00050     private:
00051         static const char *ms_label[][2];
00052         short m_iMonth;
00053     };
00054     struct Zone {
00055         Zone(int iZone);
00056         Zone(const std::string& );
00057         bool operator==(const std::string&);
00058         bool operator==(int iZone);
00059         std::string name() const;
00060         short ordinal() const;
00061     private:
00062         static int ms_offset[];
00063         static const char *ms_label[];
00064         short m_iZone, m_iZoneIdx;
00065         std::string m_sZone;
00066     };
00067 
00068     // DateTime
00069     enum {
00070         Jan = 1, Feb, Mar, Apr, May, Jun, Jul,
00071         Aug, Sep, Oct, Nov, Dec
00072     };
00073     enum {
00074         Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun
00075     };
00076 
00077     enum {
00078         GMT    = +000,
00079         UT     = +000,
00080         BST     = +100,
00081         CET    = +100,
00082         MET    = +100,
00083         EET    = +200,
00084         IST    = +200,
00085         METDST= +200,
00086         EDT    = -400,
00087         CDT    = -500,
00088         EST    = -500,
00089         CST    = -600,
00090         MDT    = -600,
00091         MST    = -700,
00092         PDT    = -700,
00093         HKT    = +800,
00094         PST    = -800,
00095         JST    = +900
00096     };
00097     DateTime();
00098     DateTime(const char*);
00099     DateTime(const std::string&);
00100     DayOfWeek dayOfWeek() const;
00101     short day() const;
00102     Month month() const;
00103     short year() const;
00104     short hour() const;
00105     short minute() const;
00106     short second() const;
00107     Zone zone() const;
00108     std::string str() const;
00109     //friend std::ostream& operator<<(std::ostream&, const DateTime&);
00110 protected:
00111     FieldValue* clone() const;
00112 private:
00113     void set(const std::string&);
00114     mutable int m_iDayOfWeek;
00115     int m_iDay, m_iMonth, m_iYear;
00116     int m_iHour, m_iMinute, m_iSecond;
00117     std::string m_zone;
00118 };
00119 
00120 
00121 }
00122 
00123 #endif