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();
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
00191 time_t GetTimeInSeconds() const;
00192
00198 long GetMicrosecond() const;
00199
00205 int GetSecond() const;
00206
00212 int GetMinute() const;
00213
00219 int GetHour() const;
00220
00226 int GetDay() const;
00227
00229 enum Months {
00230 January = 1,
00231 February,
00232 March,
00233 April,
00234 May,
00235 June,
00236 July,
00237 August,
00238 September,
00239 October,
00240 November,
00241 December
00242 };
00243
00249 Months GetMonth() const;
00250
00256 int GetYear() const;
00257
00259 enum Weekdays {
00260 Sunday,
00261 Monday,
00262 Tuesday,
00263 Wednesday,
00264 Thursday,
00265 Friday,
00266 Saturday
00267 };
00268
00274 Weekdays GetDayOfWeek() const;
00275
00281 int GetDayOfYear() const;
00282
00288 PBoolean IsPast() const;
00289
00295 PBoolean IsFuture() const;
00297
00305 static PBoolean IsDaylightSavings();
00306
00308 enum TimeZoneType {
00309 StandardTime,
00310 DaylightSavings
00311 };
00312
00314 static int GetTimeZone();
00323 static int GetTimeZone(
00324 TimeZoneType type
00325 );
00326
00332 static PString GetTimeZoneString(
00333 TimeZoneType type = StandardTime
00334 );
00336
00344 PTime operator+(
00345 const PTimeInterval & time
00346 ) const;
00347
00353 PTime & operator+=(
00354 const PTimeInterval & time
00355 );
00356
00362 PTimeInterval operator-(
00363 const PTime & time
00364 ) const;
00365
00371 PTime operator-(
00372 const PTimeInterval & time
00373 ) const;
00374
00380 PTime & operator-=(
00381 const PTimeInterval & time
00382 );
00384
00387
00388 enum TimeFormat {
00390 RFC1123,
00392 ShortISO8601,
00394 LongISO8601,
00396 LongDateTime,
00398 LongDate,
00400 LongTime,
00402 MediumDateTime,
00404 MediumDate,
00406 ShortDateTime,
00408 ShortDate,
00410 ShortTime,
00411 NumTimeStrings
00412 };
00413
00415 PString AsString(
00416 TimeFormat formatCode = RFC1123,
00417 int zone = Local
00418 ) const;
00419
00421 PString AsString(
00422 const PString & formatStr,
00423 int zone = Local
00424 ) const;
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 PString AsString(
00461 const char * formatPtr,
00462 int zone = Local
00463 ) const;
00465
00473 static PString GetTimeSeparator();
00474
00480 static PBoolean GetTimeAMPM();
00481
00487 static PString GetTimeAM();
00488
00494 static PString GetTimePM();
00495
00497 enum NameType {
00498 FullName,
00499 Abbreviated
00500 };
00501
00507 static PString GetDayName(
00508 Weekdays dayOfWeek,
00509 NameType type = FullName
00510 );
00511
00517 static PString GetDateSeparator();
00518
00524 static PString GetMonthName(
00525 Months month,
00526 NameType type = FullName
00527 );
00528
00530 enum DateOrder {
00531 MonthDayYear,
00532 DayMonthYear,
00533 YearMonthDay
00534 };
00535
00541 static DateOrder GetDateOrder();
00543
00544 static struct tm * os_localtime(const time_t * clock, struct tm * t);
00545 static struct tm * os_gmtime(const time_t * clock, struct tm * t);
00546
00547
00548
00549
00550
00551
00552
00553 protected:
00554
00556 time_t theTime;
00557 long microseconds;
00558
00559
00560
00561 #ifdef _WIN32
00562 #include "msos/ptlib/ptime.h"
00563 #else
00564 #include "unix/ptlib/ptime.h"
00565 #endif
00566 };
00567
00568
00569 #endif // PTLIB_TIME_H
00570
00571
00572