00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef PTLIB_TIME_H
00035 #define PTLIB_TIME_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041
00043
00044
00045 class PTimeInterval;
00046
00047
00053 class PTime : public PObject
00054 {
00055 PCLASSINFO(PTime, PObject);
00056
00057 public:
00063 enum {
00065 UTC = 0,
00067 GMT = UTC,
00069 Local = 9999
00070 };
00071
00075 PTime() { SetCurrentTime(); }
00076
00080 PTime(
00081 time_t tsecs,
00082 long usecs = 0
00083 ) { theTime = tsecs; microseconds = usecs; }
00084
00101 PTime(
00102 const PString & str
00103 );
00104
00108 PTime(
00109 int second,
00110 int minute,
00111 int hour,
00112 int day,
00113 int month,
00114 int year,
00115 int tz = Local
00116 );
00118
00127 PObject * Clone() const;
00128
00135 virtual Comparison Compare(
00136 const PObject & obj
00137 ) const;
00138
00142 virtual void PrintOn(
00143 ostream & strm
00144 ) const;
00145
00162 virtual void ReadFrom(
00163 istream & strm
00164 );
00166
00175 PBoolean IsValid() const;
00176
00183 PInt64 GetTimestamp() const;
00184
00187 void SetCurrentTime();
00188
00191 void SetTimestamp(
00192 time_t seconds,
00193 long usecs = 0
00194 );
00195
00202 time_t GetTimeInSeconds() const;
00203
00209 long GetMicrosecond() const;
00210
00216 int GetSecond() const;
00217
00223 int GetMinute() const;
00224
00230 int GetHour() const;
00231
00237 int GetDay() const;
00238
00240 enum Months {
00241 January = 1,
00242 February,
00243 March,
00244 April,
00245 May,
00246 June,
00247 July,
00248 August,
00249 September,
00250 October,
00251 November,
00252 December
00253 };
00254
00260 Months GetMonth() const;
00261
00267 int GetYear() const;
00268
00270 enum Weekdays {
00271 Sunday,
00272 Monday,
00273 Tuesday,
00274 Wednesday,
00275 Thursday,
00276 Friday,
00277 Saturday
00278 };
00279
00285 Weekdays GetDayOfWeek() const;
00286
00292 int GetDayOfYear() const;
00293
00299 PBoolean IsPast() const;
00300
00306 PBoolean IsFuture() const;
00308
00316 static PBoolean IsDaylightSavings();
00317
00319 enum TimeZoneType {
00320 StandardTime,
00321 DaylightSavings
00322 };
00323
00325 static int GetTimeZone();
00334 static int GetTimeZone(
00335 TimeZoneType type
00336 );
00337
00343 static PString GetTimeZoneString(
00344 TimeZoneType type = StandardTime
00345 );
00347
00355 PTime operator+(
00356 const PTimeInterval & time
00357 ) const;
00358
00364 PTime & operator+=(
00365 const PTimeInterval & time
00366 );
00367
00373 PTimeInterval operator-(
00374 const PTime & time
00375 ) const;
00376
00382 PTime operator-(
00383 const PTimeInterval & time
00384 ) const;
00385
00391 PTime & operator-=(
00392 const PTimeInterval & time
00393 );
00395
00398
00399 enum TimeFormat {
00401 RFC1123,
00403 RFC3339,
00405 ShortISO8601,
00407 LongISO8601,
00409 LongDateTime,
00411 LongDate,
00413 LongTime,
00415 MediumDateTime,
00417 MediumDate,
00419 ShortDateTime,
00421 ShortDate,
00423 ShortTime,
00425 EpochTime,
00426 NumTimeStrings
00427 };
00428
00430 PString AsString(
00431 TimeFormat formatCode = RFC1123,
00432 int zone = Local
00433 ) const;
00434
00436 PString AsString(
00437 const PString & formatStr,
00438 int zone = Local
00439 ) const;
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 PString AsString(
00478 const char * formatPtr,
00479 int zone = Local
00480 ) const;
00481
00498 bool Parse(
00499 const PString & str
00500 );
00502
00510 static PString GetTimeSeparator();
00511
00517 static PBoolean GetTimeAMPM();
00518
00524 static PString GetTimeAM();
00525
00531 static PString GetTimePM();
00532
00534 enum NameType {
00535 FullName,
00536 Abbreviated
00537 };
00538
00544 static PString GetDayName(
00545 Weekdays dayOfWeek,
00546 NameType type = FullName
00547 );
00548
00554 static PString GetDateSeparator();
00555
00561 static PString GetMonthName(
00562 Months month,
00563 NameType type = FullName
00564 );
00565
00567 enum DateOrder {
00568 MonthDayYear,
00569 DayMonthYear,
00570 YearMonthDay
00571 };
00572
00578 static DateOrder GetDateOrder();
00580
00581 static struct tm * os_localtime(const time_t * clock, struct tm * t);
00582 static struct tm * os_gmtime(const time_t * clock, struct tm * t);
00583
00584
00585
00586
00587
00588
00589
00590 protected:
00591
00593 time_t theTime;
00594 long microseconds;
00595
00596
00597
00598 #ifdef _WIN32
00599 #include "msos/ptlib/ptime.h"
00600 #else
00601 #include "unix/ptlib/ptime.h"
00602 #endif
00603 };
00604
00605
00606 #endif // PTLIB_TIME_H
00607
00608
00609