1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 |
|
---|
3 | #ifndef TIMESTAMP_H_SEEN
|
---|
4 | #define TIMESTAMP_H_SEEN
|
---|
5 |
|
---|
6 | // Classe TimeStamp (Date+heure)
|
---|
7 | //
|
---|
8 | // R. Ansari UPS+LAL IN2P3/CNRS 2005
|
---|
9 | // Code recupere en partie ds dates.h dates.cc (classe Date) / E. Aubourg 1995-2000
|
---|
10 |
|
---|
11 |
|
---|
12 | #include "machdefs.h"
|
---|
13 | #include <string>
|
---|
14 | #include <iostream>
|
---|
15 |
|
---|
16 | namespace SOPHYA {
|
---|
17 |
|
---|
18 | //! Class representing date and time
|
---|
19 | class TimeStamp {
|
---|
20 | public:
|
---|
21 | /* Pour utilisation ulterieure
|
---|
22 | //! GMT / local time enum
|
---|
23 | enum {kGMTTime=0, kLocalTime=1};
|
---|
24 | */
|
---|
25 | //! Month name enum
|
---|
26 | enum Month {month_January=1, month_February, month_March, month_April, month_May, month_June, month_July,
|
---|
27 | month_August, month_September, month_October, month_November, month_December};
|
---|
28 |
|
---|
29 | //! Default Constructor : current date and time (GMT)
|
---|
30 | TimeStamp();
|
---|
31 | TimeStamp(TimeStamp const & ts);
|
---|
32 | //! Constructor with specification of number of days since 0 Jan 1901 0h TU
|
---|
33 | TimeStamp(double days);
|
---|
34 | //! Constructor with specification of day,month,year,hour,minutes,seconds
|
---|
35 | TimeStamp(int year, int month, int day, int hour, int min, double sec);
|
---|
36 | //! Constructor with specification of date & time in the format YYYY/MM/DD hh:mm:ss
|
---|
37 | TimeStamp(string& date, string& hour);
|
---|
38 | TimeStamp(const char* date, const char* hour);
|
---|
39 |
|
---|
40 | //! Set the value of the time stamp copying from "ts"
|
---|
41 | void Set(TimeStamp const & ts);
|
---|
42 | //! Sets the value of the time stamp from the number of days since 0 Jan 1901 0h TU
|
---|
43 | void Set(double days);
|
---|
44 | //! initialize with current date and time (GMT)
|
---|
45 | void SetNow();
|
---|
46 |
|
---|
47 | //! The equal (set) operator
|
---|
48 | inline TimeStamp& operator= (TimeStamp const & ts)
|
---|
49 | { Set(ts); return(*this); }
|
---|
50 |
|
---|
51 | //! Sets the value of the date (days)
|
---|
52 | void SetDate(int year, int month, int day);
|
---|
53 | //! Sets the value of the date (format: DD/MM/YYYY)
|
---|
54 | void SetDate(const char* date);
|
---|
55 | //! Sets the value of the date (format: DD/MM/YYYY)
|
---|
56 | inline void SetDate(string const& date) { SetDate(date.c_str()); }
|
---|
57 |
|
---|
58 | //! Sets the value of the time of day (hours)
|
---|
59 | void SetHour(int hour, int min, double sec);
|
---|
60 | //! Sets the value of the time of day (format: hh:mm:ss[.ss])
|
---|
61 | void SetHour(const char* hour);
|
---|
62 | //! Sets the value of the time of day (format: hh:mm:ss[.ss])
|
---|
63 | inline void SetHour(string const& hour) { SetHour(hour.c_str()); }
|
---|
64 |
|
---|
65 | //! Return the date (Year, Month, Day)
|
---|
66 | void GetDate(int& year, int& month, int& day) const;
|
---|
67 | //! Return the time of the day
|
---|
68 | void GetHour(int& hour, int& min, double& sec) const;
|
---|
69 |
|
---|
70 | //! Return the value of the TimeStamp as days.fraction_days since 0 Jan 1901
|
---|
71 | double ToDays() const;
|
---|
72 | //! Conversion operator to double
|
---|
73 | inline operator double() const { return ToDays(); }
|
---|
74 |
|
---|
75 | //! Return the timestamp in string format
|
---|
76 | string ToString() const;
|
---|
77 |
|
---|
78 | /*! Prints the date/time in string format on \b cout */
|
---|
79 | inline void Print() const { Print(cout); }
|
---|
80 | /*! Prints the date/time in string format on stream \b os */
|
---|
81 | virtual void Print(ostream& os) const;
|
---|
82 |
|
---|
83 | //!
|
---|
84 | //! Number of days in a given month
|
---|
85 | static int MonthDays(int year, int month);
|
---|
86 | //! Number of days in a given year
|
---|
87 | static int YearDays(int annee);
|
---|
88 | //! Number of days since 0 janvier 1901 0h TU
|
---|
89 | static int_8 ConvertToDays(int year, int month, int day);
|
---|
90 |
|
---|
91 |
|
---|
92 | protected:
|
---|
93 | r_8 mSeconds; // Number of seconds since 00:00:00
|
---|
94 | int_8 mDays; // Number of days since 0 Jan 1901
|
---|
95 | };
|
---|
96 |
|
---|
97 | /*! operator << overloading - Prints date/time in string format on \b os*/
|
---|
98 | inline ostream& operator << (ostream& s, TimeStamp const & ts)
|
---|
99 | { ts.Print(s); return(s); }
|
---|
100 |
|
---|
101 | } // namespace SOPHYA
|
---|
102 |
|
---|
103 | #endif
|
---|