📄 ptime.h
字号:
/* * ptime.h * * Time and date class. * * Portable Windows Library * * Copyright (c) 1993-1998 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: ptime.h,v $ * Revision 1.34 2003/09/17 05:41:59 csoutheren * Removed recursive includes * * Revision 1.33 2003/09/17 01:18:02 csoutheren * Removed recursive include file system and removed all references * to deprecated coooperative threading support * * Revision 1.32 2002/12/10 04:45:14 robertj * Added support in PTime for ISO 8601 format. * * Revision 1.31 2002/10/29 00:07:03 robertj * Added IsValid() function to indicate that a PTime is set correctly. * * Revision 1.30 2002/09/16 01:08:59 robertj * Added #define so can select if #pragma interface/implementation is used on * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. * * Revision 1.29 2001/05/22 12:49:32 robertj * Did some seriously wierd rewrite of platform headers to eliminate the * stupid GNU compiler warning about braces not matching. * * Revision 1.28 2000/04/29 08:14:52 robertj * Added some documentation on string formats that can be parsed into a time. * * Revision 1.27 2000/04/29 04:49:00 robertj * Added microseconds to string output. * * Revision 1.26 2000/04/05 02:50:16 robertj * Added microseconds to PTime class. * * Revision 1.25 1999/03/09 02:59:50 robertj * Changed comments to doc++ compatible documentation. * * Revision 1.24 1999/02/16 08:11:10 robertj * MSVC 6.0 compatibility changes. * * Revision 1.23 1998/09/23 06:21:15 robertj * Added open source copyright license. * * Revision 1.22 1998/01/04 08:04:27 robertj * Changed gmtime and locatime to use operating system specific functions. * * Revision 1.21 1997/01/12 04:21:40 robertj * Added IsPast() and IsFuture() functions for time comparison. * * Revision 1.20 1996/05/09 12:16:06 robertj * Fixed syntax error found by Mac platform. * * Revision 1.19 1996/02/15 14:47:34 robertj * Fixed bugs in time zone compensation (some in the C library). * * Revision 1.18 1996/02/13 12:58:43 robertj * Changed GetTimeZone() so can specify standard/daylight time. * * Revision 1.17 1996/02/08 12:13:03 robertj * Changed zone parameter in PTime to indicate the time zone as minutes not enum. * Staticised some functions that are system global. * * Revision 1.16 1996/02/03 11:04:52 robertj * Added string constructor for times, parses date/time from string. * * Revision 1.15 1996/01/03 11:09:34 robertj * Added Universal Time and Time Zones to PTime class. * * Revision 1.14 1995/06/17 11:13:10 robertj * Documentation update. * * Revision 1.13 1995/03/14 12:42:18 robertj * Updated documentation to use HTML codes. * * Revision 1.12 1995/01/11 09:45:12 robertj * Documentation and normalisation. * * Revision 1.11 1995/01/09 12:34:05 robertj * Removed unnecesary return value from I/O functions. * * Revision 1.10 1994/08/23 11:32:52 robertj * Oops * * Revision 1.9 1994/08/22 00:46:48 robertj * Added pragma fro GNU C++ compiler. * * Revision 1.8 1994/07/27 05:58:07 robertj * Synchronisation. * * Revision 1.7 1994/06/25 11:55:15 robertj * Unix version synchronisation. * * Revision 1.6 1994/01/13 03:16:09 robertj * Added function to return time as a string. * * Revision 1.5 1994/01/03 04:42:23 robertj * Mass changes to common container classes and interactors etc etc etc. * * Revision 1.4 1993/12/31 06:45:38 robertj * Made inlines optional for debugging purposes. * * Revision 1.3 1993/08/27 18:17:47 robertj * Made time functions common to all platforms. * Moved timer resolution function to PTimeInterval wher it belongs. * * Revision 1.2 1993/07/14 12:49:16 robertj * Fixed RCS keywords. * */#ifndef _PTIME#define _PTIME#ifdef P_USE_PRAGMA#pragma interface#endif#include <time.h>///////////////////////////////////////////////////////////////////////////////// System time and date classclass PTimeInterval;/**This class defines an absolute time and date. It has a number of time and date rendering and manipulation functions. It is based on the standard C library functions for time. Thus it is based on a number of seconds since 1 January 1970. */class PTime : public PObject{ PCLASSINFO(PTime, PObject); public: /**@name Construction */ //@{ /** Time Zone special codes. The value for a time zone is usually in minutes from UTC, this enum are special values for specific areas. */ enum { /// Universal Coordinated Time. UTC = 0, /// Greenwich Mean Time, effectively UTC. GMT = UTC, /// Local Time. Local = 9999 }; /**Create a time object instance. This initialises the time with the current time in the current time zone. */ PTime(); /**Create a time object instance. This initialises the time to the specified time. */ PTime( time_t tsecs, /// Time in seconds since 00:00:00 1/1/70 UTC long usecs = 0 ) { theTime = tsecs; microseconds = usecs; } /**Create a time object instance. This initialises the time to the specified time, parsed from the string. The string may be in many different formats, for example: "5/03/1999 12:34:56" "15/06/1999 12:34:56" "15/06/01 12:34:56 PST" "5/06/02 12:34:56" "5/23/1999 12:34am" "5/23/00 12:34am" "1999/23/04 12:34:56" "Mar 3, 1999 12:34pm" "3 Jul 2004 12:34pm" "12:34:56 5 December 1999" "10 minutes ago" "2 weeks" */ PTime( const PString & str /// Time and data as a string ); /**Create a time object instance. This initialises the time to the specified time. */ PTime( int second, /// Second from 0 to 59. int minute, /// Minute from 0 to 59. int hour, /// Hour from 0 to 23. int day, /// Day of month from 1 to 31. int month, /// Month from 1 to 12. int year, /// Year from 1970 to 2038 int tz = Local /// local time or UTC ); //@} /**@name Overrides from class PObject */ //@{ /**Create a copy of the time on the heap. It is the responsibility of the caller to delete the created object. @return pointer to new time. */ PObject * Clone() const; /**Determine the relative rank of the specified times. This ranks the times as you would expect. @return rank of the two times. */ virtual Comparison Compare( const PObject & obj /// Other time to compare against. ) const; /**Output the time to the stream. This uses the #AsString()# function with the #ShortDateTime# parameter. */ virtual void PrintOn( ostream & strm /// Stream to output the time to. ) const; /**Input the time from the specified stream. If a parse error occurs the time is set to the current time. The string may be in many different formats, for example: "5/03/1999 12:34:56" "15/06/1999 12:34:56" "15/06/01 12:34:56 PST" "5/06/02 12:34:56" "5/23/1999 12:34am" "5/23/00 12:34am" "1999/23/04 12:34:56" "Mar 3, 1999 12:34pm" "3 Jul 2004 12:34pm" "12:34:56 5 December 1999" "10 minutes ago" "2 weeks" */ virtual void ReadFrom( istream & strm /// Stream to input the time from. ); //@} /**@name Access functions */ //@{ /**Determine if the timestamp is valid. This will return TRUE if the timestamp can be represented as a time in the epoch. The epoch is the 1st January 1970. In practice this means the time is > 13 hours to allow for time zones. */ BOOL IsValid() const; /**Get the total microseconds since the epoch. The epoch is the 1st January 1970. @return microseconds. */ PInt64 GetTimestamp() const; /**Get the total seconds since the epoch. The epoch is the 1st January 1970. @return seconds. */ time_t GetTimeInSeconds() const; /**Get the microsecond part of the time. @return integer in range 0..999999. */ long GetMicrosecond() const; /**Get the second of the time. @return integer in range 0..59. */ int GetSecond() const; /**Get the minute of the time. @return integer in range 0..59. */ int GetMinute() const; /**Get the hour of the time. @return integer in range 0..23. */ int GetHour() const; /**Get the day of the month of the date. @return integer in range 1..31. */ int GetDay() const; /// Month codes. enum Months { January = 1, February, March,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -