diff options
Diffstat (limited to 'linden/indra/llcommon/lldate.cpp')
-rw-r--r-- | linden/indra/llcommon/lldate.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/linden/indra/llcommon/lldate.cpp b/linden/indra/llcommon/lldate.cpp index ccc314d..47e5370 100644 --- a/linden/indra/llcommon/lldate.cpp +++ b/linden/indra/llcommon/lldate.cpp | |||
@@ -72,6 +72,54 @@ std::string LLDate::asString() const | |||
72 | return stream.str(); | 72 | return stream.str(); |
73 | } | 73 | } |
74 | 74 | ||
75 | //@ brief Converts time in seconds since EPOCH | ||
76 | // to RFC 1123 compliant date format | ||
77 | // E.g. 1184797044.037586 == Wednesday, 18 Jul 2007 22:17:24 GMT | ||
78 | // in RFC 1123. HTTP dates are always in GMT and RFC 1123 | ||
79 | // is one of the standards used and the prefered format | ||
80 | std::string LLDate::asRFC1123() const | ||
81 | { | ||
82 | std::ostringstream stream; | ||
83 | toHTTPDateStream(stream); | ||
84 | return stream.str(); | ||
85 | } | ||
86 | |||
87 | void LLDate::toHTTPDateStream(std::ostream& s) const | ||
88 | { | ||
89 | // http://apr.apache.org/docs/apr/0.9/group__apr__time.html | ||
90 | apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC); | ||
91 | |||
92 | apr_time_exp_t exp_time ; //Apache time module | ||
93 | |||
94 | if (apr_time_exp_gmt(&exp_time, time) != APR_SUCCESS) | ||
95 | { | ||
96 | // Return Epoch UTC date | ||
97 | s << "Thursday, 01 Jan 1970 00:00:00 GMT" ; | ||
98 | return; | ||
99 | } | ||
100 | |||
101 | s << std::dec << std::setfill('0'); | ||
102 | #if( LL_WINDOWS || __GNUC__ > 2) | ||
103 | s << std::right ; | ||
104 | #else | ||
105 | s.setf(ios::right); | ||
106 | #endif | ||
107 | std::string day = weekdays[exp_time.tm_wday]; | ||
108 | std::string month = months[exp_time.tm_mon]; | ||
109 | |||
110 | s << std::setw(day.length()) << (day) | ||
111 | << ", " << std::setw(2) << (exp_time.tm_mday) | ||
112 | << ' ' << std::setw(month.length()) << (month) | ||
113 | << ' ' << std::setw(4) << (exp_time.tm_year + 1900) | ||
114 | << ' ' << std::setw(2) << (exp_time.tm_hour) | ||
115 | << ':' << std::setw(2) << (exp_time.tm_min) | ||
116 | << ':' << std::setw(2) << (exp_time.tm_sec) | ||
117 | << " GMT"; | ||
118 | |||
119 | // RFC 1123 date does not use microseconds | ||
120 | llinfos << "Date in RFC 1123 format is " << s << llendl; | ||
121 | } | ||
122 | |||
75 | void LLDate::toStream(std::ostream& s) const | 123 | void LLDate::toStream(std::ostream& s) const |
76 | { | 124 | { |
77 | apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC); | 125 | apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC); |