Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / Core / NptTime.h
blob64b244e69a2653b6e7d556561479e0ee7ac20cff
1 /*****************************************************************
3 | Neptune - Time
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ****************************************************************/
32 #ifndef _NPT_TIME_H_
33 #define _NPT_TIME_H_
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptTypes.h"
39 #include "NptStrings.h"
41 /*----------------------------------------------------------------------
42 | constants
43 +---------------------------------------------------------------------*/
44 #define NPT_DATETIME_YEAR_MIN 1901
45 #define NPT_DATETIME_YEAR_MAX 2262
47 /*----------------------------------------------------------------------
48 | NPT_TimeStamp
49 +---------------------------------------------------------------------*/
50 class NPT_TimeStamp
52 public:
53 // methods
54 NPT_TimeStamp(const NPT_TimeStamp& timestamp);
55 NPT_TimeStamp() : m_NanoSeconds(0) {}
56 NPT_TimeStamp(NPT_Int64 nanoseconds) : m_NanoSeconds(nanoseconds) {}
57 NPT_TimeStamp(float seconds);
58 NPT_TimeStamp(double seconds);
59 NPT_TimeStamp& operator=(const NPT_TimeStamp&) = default;
60 NPT_TimeStamp& operator+=(const NPT_TimeStamp& time_stamp);
61 NPT_TimeStamp& operator-=(const NPT_TimeStamp& time_stamp);
62 bool operator==(const NPT_TimeStamp& t) const { return m_NanoSeconds == t.m_NanoSeconds; }
63 bool operator!=(const NPT_TimeStamp& t) const { return m_NanoSeconds != t.m_NanoSeconds; }
64 bool operator> (const NPT_TimeStamp& t) const { return m_NanoSeconds > t.m_NanoSeconds; }
65 bool operator< (const NPT_TimeStamp& t) const { return m_NanoSeconds < t.m_NanoSeconds; }
66 bool operator>=(const NPT_TimeStamp& t) const { return m_NanoSeconds >= t.m_NanoSeconds; }
67 bool operator<=(const NPT_TimeStamp& t) const { return m_NanoSeconds <= t.m_NanoSeconds; }
69 // accessors
70 void SetNanos(NPT_Int64 nanoseconds) { m_NanoSeconds = nanoseconds; }
71 void SetMicros(NPT_Int64 micros) { m_NanoSeconds = micros * 1000; }
72 void SetMillis(NPT_Int64 millis) { m_NanoSeconds = millis * 1000000; }
73 void SetSeconds(NPT_Int64 seconds) { m_NanoSeconds = seconds * 1000000000; }
75 // conversion
76 operator double() const { return (double)m_NanoSeconds/1E9; }
77 void FromNanos(NPT_Int64 nanoseconds) { m_NanoSeconds = nanoseconds; }
78 NPT_Int64 ToNanos() const { return m_NanoSeconds; }
79 NPT_Int64 ToMicros() const { return m_NanoSeconds/1000; }
80 NPT_Int64 ToMillis() const { return m_NanoSeconds/1000000; }
81 NPT_Int64 ToSeconds() const { return m_NanoSeconds/1000000000; }
83 private:
84 // members
85 NPT_Int64 m_NanoSeconds;
88 /*----------------------------------------------------------------------
89 | operator+
90 +---------------------------------------------------------------------*/
91 inline
92 NPT_TimeStamp
93 operator+(const NPT_TimeStamp& t1, const NPT_TimeStamp& t2)
95 NPT_TimeStamp t = t1;
96 return t += t2;
99 /*----------------------------------------------------------------------
100 | operator-
101 +---------------------------------------------------------------------*/
102 inline
103 NPT_TimeStamp
104 operator-(const NPT_TimeStamp& t1, const NPT_TimeStamp& t2)
106 NPT_TimeStamp t = t1;
107 return t -= t2;
110 /*----------------------------------------------------------------------
111 | NPT_TimeInterval
112 +---------------------------------------------------------------------*/
113 typedef NPT_TimeStamp NPT_TimeInterval;
115 /*----------------------------------------------------------------------
116 | NPT_DateTime
117 +---------------------------------------------------------------------*/
118 class NPT_DateTime {
119 public:
120 // types
121 enum Format {
122 FORMAT_ANSI,
123 FORMAT_W3C,
124 FORMAT_RFC_1123, // RFC 822 updated by RFC 1123
125 FORMAT_RFC_1036 // RFC 850 updated by RFC 1036
128 enum FormatFlags {
129 FLAG_EMIT_FRACTION = 1,
130 FLAG_EXTENDED_PRECISION = 2
133 // class methods
134 NPT_Int32 GetLocalTimeZone();
136 // constructors
137 NPT_DateTime();
138 NPT_DateTime(const NPT_TimeStamp& timestamp, bool local=false);
140 // methods
141 NPT_Result ChangeTimeZone(NPT_Int32 timezone);
142 NPT_Result FromTimeStamp(const NPT_TimeStamp& timestamp, bool local=false);
143 NPT_Result ToTimeStamp(NPT_TimeStamp& timestamp) const;
144 NPT_Result FromString(const char* date, Format format = FORMAT_ANSI);
145 NPT_String ToString(Format format = FORMAT_ANSI, NPT_Flags flags=0) const;
147 // members
148 NPT_Int32 m_Year; // year
149 NPT_Int32 m_Month; // month of the year (1-12)
150 NPT_Int32 m_Day; // day of the month (1-31)
151 NPT_Int32 m_Hours; // hours (0-23)
152 NPT_Int32 m_Minutes; // minutes (0-59)
153 NPT_Int32 m_Seconds; // seconds (0-59)
154 NPT_Int32 m_NanoSeconds; // nanoseconds (0-999999999)
155 NPT_Int32 m_TimeZone; // minutes offset from GMT
158 #endif // _NPT_TIME_H_