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 PString AsString(
00459 const char * formatPtr,
00460 int zone = Local
00461 ) const;
00463
00471 static PString GetTimeSeparator();
00472
00478 static PBoolean GetTimeAMPM();
00479
00485 static PString GetTimeAM();
00486
00492 static PString GetTimePM();
00493
00495 enum NameType {
00496 FullName,
00497 Abbreviated
00498 };
00499
00505 static PString GetDayName(
00506 Weekdays dayOfWeek,
00507 NameType type = FullName
00508 );
00509
00515 static PString GetDateSeparator();
00516
00522 static PString GetMonthName(
00523 Months month,
00524 NameType type = FullName
00525 );
00526
00528 enum DateOrder {
00529 MonthDayYear,
00530 DayMonthYear,
00531 YearMonthDay
00532 };
00533
00539 static DateOrder GetDateOrder();
00541
00542 static struct tm * os_localtime(const time_t * clock, struct tm * t);
00543 static struct tm * os_gmtime(const time_t * clock, struct tm * t);
00544
00545
00546
00547
00548
00549
00550
00551 protected:
00552
00554 time_t theTime;
00555 long microseconds;
00556
00557
00558
00559 #ifdef _WIN32
00560 #include "msos/ptlib/ptime.h"
00561 #else
00562 #include "unix/ptlib/ptime.h"
00563 #endif
00564 };
00565
00566
00567 #endif // PTLIB_TIME_H
00568
00569
00570