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 _PTIME
00035 #define _PTIME
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041
00042 #include <time.h>
00043
00044
00046
00047
00048 class PTimeInterval;
00049
00050
00056 class PTime : public PObject
00057 {
00058 PCLASSINFO(PTime, PObject);
00059
00060 public:
00066 enum {
00068 UTC = 0,
00070 GMT = UTC,
00072 Local = 9999
00073 };
00074
00078 PTime();
00079
00083 PTime(
00084 time_t tsecs,
00085 long usecs = 0
00086 ) { theTime = tsecs; microseconds = usecs; }
00087
00104 PTime(
00105 const PString & str
00106 );
00107
00111 PTime(
00112 int second,
00113 int minute,
00114 int hour,
00115 int day,
00116 int month,
00117 int year,
00118 int tz = Local
00119 );
00121
00130 PObject * Clone() const;
00131
00138 virtual Comparison Compare(
00139 const PObject & obj
00140 ) const;
00141
00145 virtual void PrintOn(
00146 ostream & strm
00147 ) const;
00148
00165 virtual void ReadFrom(
00166 istream & strm
00167 );
00169
00178 PBoolean IsValid() const;
00179
00186 PInt64 GetTimestamp() const;
00187
00194 time_t GetTimeInSeconds() const;
00195
00201 long GetMicrosecond() const;
00202
00208 int GetSecond() const;
00209
00215 int GetMinute() const;
00216
00222 int GetHour() const;
00223
00229 int GetDay() const;
00230
00232 enum Months {
00233 January = 1,
00234 February,
00235 March,
00236 April,
00237 May,
00238 June,
00239 July,
00240 August,
00241 September,
00242 October,
00243 November,
00244 December
00245 };
00246
00252 Months GetMonth() const;
00253
00259 int GetYear() const;
00260
00262 enum Weekdays {
00263 Sunday,
00264 Monday,
00265 Tuesday,
00266 Wednesday,
00267 Thursday,
00268 Friday,
00269 Saturday
00270 };
00271
00277 Weekdays GetDayOfWeek() const;
00278
00284 int GetDayOfYear() const;
00285
00291 PBoolean IsPast() const;
00292
00298 PBoolean IsFuture() const;
00300
00308 static PBoolean IsDaylightSavings();
00309
00311 enum TimeZoneType {
00312 StandardTime,
00313 DaylightSavings
00314 };
00315
00317 static int GetTimeZone();
00326 static int GetTimeZone(
00327 TimeZoneType type
00328 );
00329
00335 static PString GetTimeZoneString(
00336 TimeZoneType type = StandardTime
00337 );
00339
00347 PTime operator+(
00348 const PTimeInterval & time
00349 ) const;
00350
00356 PTime & operator+=(
00357 const PTimeInterval & time
00358 );
00359
00365 PTimeInterval operator-(
00366 const PTime & time
00367 ) const;
00368
00374 PTime operator-(
00375 const PTimeInterval & time
00376 ) const;
00377
00383 PTime & operator-=(
00384 const PTimeInterval & time
00385 );
00387
00390
00391 enum TimeFormat {
00393 RFC1123,
00395 ShortISO8601,
00397 LongISO8601,
00399 LongDateTime,
00401 LongDate,
00403 LongTime,
00405 MediumDateTime,
00407 MediumDate,
00409 ShortDateTime,
00411 ShortDate,
00413 ShortTime,
00414 NumTimeStrings
00415 };
00416
00418 PString AsString(
00419 TimeFormat formatCode = RFC1123,
00420 int zone = Local
00421 ) const;
00422
00424 PString AsString(
00425 const PString & formatStr,
00426 int zone = Local
00427 ) const;
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
00461 PString AsString(
00462 const char * formatPtr,
00463 int zone = Local
00464 ) const;
00466
00474 static PString GetTimeSeparator();
00475
00481 static PBoolean GetTimeAMPM();
00482
00488 static PString GetTimeAM();
00489
00495 static PString GetTimePM();
00496
00498 enum NameType {
00499 FullName,
00500 Abbreviated
00501 };
00502
00508 static PString GetDayName(
00509 Weekdays dayOfWeek,
00510 NameType type = FullName
00511 );
00512
00518 static PString GetDateSeparator();
00519
00525 static PString GetMonthName(
00526 Months month,
00527 NameType type = FullName
00528 );
00529
00531 enum DateOrder {
00532 MonthDayYear,
00533 DayMonthYear,
00534 YearMonthDay
00535 };
00536
00542 static DateOrder GetDateOrder();
00544
00545 static struct tm * os_localtime(const time_t * clock, struct tm * t);
00546 static struct tm * os_gmtime(const time_t * clock, struct tm * t);
00547
00548
00549
00550
00551
00552
00553
00554 protected:
00555
00557 time_t theTime;
00558 long microseconds;
00559
00560
00561
00562 #ifdef _WIN32
00563 #include "msos/ptlib/ptime.h"
00564 #else
00565 #include "unix/ptlib/ptime.h"
00566 #endif
00567 };
00568
00569 #endif
00570
00571