aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/lldate.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/lldate.h')
-rw-r--r--linden/indra/llcommon/lldate.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/linden/indra/llcommon/lldate.h b/linden/indra/llcommon/lldate.h
new file mode 100644
index 0000000..8fb6d67
--- /dev/null
+++ b/linden/indra/llcommon/lldate.h
@@ -0,0 +1,121 @@
1/**
2 * @file lldate.h
3 * @author Phoenix
4 * @date 2006-02-05
5 * @brief Declaration of a simple date class.
6 *
7 * Copyright (c) 2006-2007, Linden Research, Inc.
8 *
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlife.com/developers/opensource/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlife.com/developers/opensource/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 */
29
30#ifndef LL_LLDATE_H
31#define LL_LLDATE_H
32
33#include <iosfwd>
34
35#include "stdtypes.h"
36
37/**
38 * @class LLDate
39 * @brief This class represents a particular point in time in UTC.
40 *
41 * The date class represents a point in time after epoch - 1970-01-01.
42 */
43class LLDate
44{
45public:
46 /**
47 * @brief Construct a date equal to epoch.
48 */
49 LLDate();
50
51 /**
52 * @brief Construct a date equal to epoch.
53 */
54 LLDate(const LLDate& date);
55
56 /**
57 * @brief Construct a date from a seconds since epoch value.
58 *
59 * @pararm seconds_since_epoch The number of seconds since UTC epoch.
60 */
61 LLDate(F64 seconds_since_epoch);
62
63 /**
64 * @brief Construct a date from a string representation
65 *
66 * The date is constructed in the <code>fromString()</code>
67 * method. See that method for details of supported formats.
68 * If that method fails to parse the date, the date is set to epoch.
69 * @param iso8601_date An iso-8601 compatible representation of the date.
70 */
71 LLDate(const std::string& iso8601_date);
72
73 /**
74 * @brief Return the date as in ISO-8601 string.
75 *
76 * @return A string representation of the date.
77 */
78 std::string asString() const;
79 void toStream(std::ostream&) const;
80 /**
81 * @brief Set the date from an ISO-8601 string.
82 *
83 * The parser only supports strings conforming to
84 * YYYYF-MM-DDTHH:MM:SS.FFZ where Y is year, M is month, D is day,
85 * H is hour, M is minute, S is second, F is sub-second, and all
86 * other characters are literal.
87 * If this method fails to parse the date, the previous date is
88 * retained.
89 * @param iso8601_date An iso-8601 compatible representation of the date.
90 * @return Returns true if the string was successfully parsed.
91 */
92 bool fromString(const std::string& iso8601_date);
93 bool fromStream(std::istream&);
94
95 /**
96 * @brief Return the date in seconds since epoch.
97 *
98 * @return The number of seconds since epoch UTC.
99 */
100 F64 secondsSinceEpoch() const;
101
102 /**
103 * @brief Set the date in seconds since epoch.
104 *
105 * @param seconds The number of seconds since epoch UTC.
106 */
107 void secondsSinceEpoch(F64 seconds);
108
109private:
110 F64 mSecondsSinceEpoch;
111};
112
113
114// Helper function to stream out a date
115std::ostream& operator<<(std::ostream& s, const LLDate& date);
116
117// Helper function to stream in a date
118std::istream& operator>>(std::istream& s, LLDate& date);
119
120
121#endif // LL_LLDATE_H