|
||||
File indexing completed on 2024-11-15 09:01:19
0001 // Copyright 2018 The Abseil Authors. 0002 // 0003 // Licensed under the Apache License, Version 2.0 (the "License"); 0004 // you may not use this file except in compliance with the License. 0005 // You may obtain a copy of the License at 0006 // 0007 // https://www.apache.org/licenses/LICENSE-2.0 0008 // 0009 // Unless required by applicable law or agreed to in writing, software 0010 // distributed under the License is distributed on an "AS IS" BASIS, 0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 // See the License for the specific language governing permissions and 0013 // limitations under the License. 0014 // 0015 // ----------------------------------------------------------------------------- 0016 // File: civil_time.h 0017 // ----------------------------------------------------------------------------- 0018 // 0019 // This header file defines abstractions for computing with "civil time". 0020 // The term "civil time" refers to the legally recognized human-scale time 0021 // that is represented by the six fields `YYYY-MM-DD hh:mm:ss`. A "date" 0022 // is perhaps the most common example of a civil time (represented here as 0023 // an `absl::CivilDay`). 0024 // 0025 // Modern-day civil time follows the Gregorian Calendar and is a 0026 // time-zone-independent concept: a civil time of "2015-06-01 12:00:00", for 0027 // example, is not tied to a time zone. Put another way, a civil time does not 0028 // map to a unique point in time; a civil time must be mapped to an absolute 0029 // time *through* a time zone. 0030 // 0031 // Because a civil time is what most people think of as "time," it is common to 0032 // map absolute times to civil times to present to users. 0033 // 0034 // Time zones define the relationship between absolute and civil times. Given an 0035 // absolute or civil time and a time zone, you can compute the other time: 0036 // 0037 // Civil Time = F(Absolute Time, Time Zone) 0038 // Absolute Time = G(Civil Time, Time Zone) 0039 // 0040 // The Abseil time library allows you to construct such civil times from 0041 // absolute times; consult time.h for such functionality. 0042 // 0043 // This library provides six classes for constructing civil-time objects, and 0044 // provides several helper functions for rounding, iterating, and performing 0045 // arithmetic on civil-time objects, while avoiding complications like 0046 // daylight-saving time (DST): 0047 // 0048 // * `absl::CivilSecond` 0049 // * `absl::CivilMinute` 0050 // * `absl::CivilHour` 0051 // * `absl::CivilDay` 0052 // * `absl::CivilMonth` 0053 // * `absl::CivilYear` 0054 // 0055 // Example: 0056 // 0057 // // Construct a civil-time object for a specific day 0058 // const absl::CivilDay cd(1969, 07, 20); 0059 // 0060 // // Construct a civil-time object for a specific second 0061 // const absl::CivilSecond cd(2018, 8, 1, 12, 0, 1); 0062 // 0063 // Note: In C++14 and later, this library is usable in a constexpr context. 0064 // 0065 // Example: 0066 // 0067 // // Valid in C++14 0068 // constexpr absl::CivilDay cd(1969, 07, 20); 0069 0070 #ifndef ABSL_TIME_CIVIL_TIME_H_ 0071 #define ABSL_TIME_CIVIL_TIME_H_ 0072 0073 #include <iosfwd> 0074 #include <string> 0075 0076 #include "absl/base/config.h" 0077 #include "absl/strings/string_view.h" 0078 #include "absl/time/internal/cctz/include/cctz/civil_time.h" 0079 0080 namespace absl { 0081 ABSL_NAMESPACE_BEGIN 0082 0083 namespace time_internal { 0084 struct second_tag : cctz::detail::second_tag {}; 0085 struct minute_tag : second_tag, cctz::detail::minute_tag {}; 0086 struct hour_tag : minute_tag, cctz::detail::hour_tag {}; 0087 struct day_tag : hour_tag, cctz::detail::day_tag {}; 0088 struct month_tag : day_tag, cctz::detail::month_tag {}; 0089 struct year_tag : month_tag, cctz::detail::year_tag {}; 0090 } // namespace time_internal 0091 0092 // ----------------------------------------------------------------------------- 0093 // CivilSecond, CivilMinute, CivilHour, CivilDay, CivilMonth, CivilYear 0094 // ----------------------------------------------------------------------------- 0095 // 0096 // Each of these civil-time types is a simple value type with the same 0097 // interface for construction and the same six accessors for each of the civil 0098 // time fields (year, month, day, hour, minute, and second, aka YMDHMS). These 0099 // classes differ only in their alignment, which is indicated by the type name 0100 // and specifies the field on which arithmetic operates. 0101 // 0102 // CONSTRUCTION 0103 // 0104 // Each of the civil-time types can be constructed in two ways: by directly 0105 // passing to the constructor up to six integers representing the YMDHMS fields, 0106 // or by copying the YMDHMS fields from a differently aligned civil-time type. 0107 // Omitted fields are assigned their minimum valid value. Hours, minutes, and 0108 // seconds will be set to 0, month and day will be set to 1. Since there is no 0109 // minimum year, the default is 1970. 0110 // 0111 // Examples: 0112 // 0113 // absl::CivilDay default_value; // 1970-01-01 00:00:00 0114 // 0115 // absl::CivilDay a(2015, 2, 3); // 2015-02-03 00:00:00 0116 // absl::CivilDay b(2015, 2, 3, 4, 5, 6); // 2015-02-03 00:00:00 0117 // absl::CivilDay c(2015); // 2015-01-01 00:00:00 0118 // 0119 // absl::CivilSecond ss(2015, 2, 3, 4, 5, 6); // 2015-02-03 04:05:06 0120 // absl::CivilMinute mm(ss); // 2015-02-03 04:05:00 0121 // absl::CivilHour hh(mm); // 2015-02-03 04:00:00 0122 // absl::CivilDay d(hh); // 2015-02-03 00:00:00 0123 // absl::CivilMonth m(d); // 2015-02-01 00:00:00 0124 // absl::CivilYear y(m); // 2015-01-01 00:00:00 0125 // 0126 // m = absl::CivilMonth(y); // 2015-01-01 00:00:00 0127 // d = absl::CivilDay(m); // 2015-01-01 00:00:00 0128 // hh = absl::CivilHour(d); // 2015-01-01 00:00:00 0129 // mm = absl::CivilMinute(hh); // 2015-01-01 00:00:00 0130 // ss = absl::CivilSecond(mm); // 2015-01-01 00:00:00 0131 // 0132 // Each civil-time class is aligned to the civil-time field indicated in the 0133 // class's name after normalization. Alignment is performed by setting all the 0134 // inferior fields to their minimum valid value (as described above). The 0135 // following are examples of how each of the six types would align the fields 0136 // representing November 22, 2015 at 12:34:56 in the afternoon. (Note: the 0137 // string format used here is not important; it's just a shorthand way of 0138 // showing the six YMDHMS fields.) 0139 // 0140 // absl::CivilSecond : 2015-11-22 12:34:56 0141 // absl::CivilMinute : 2015-11-22 12:34:00 0142 // absl::CivilHour : 2015-11-22 12:00:00 0143 // absl::CivilDay : 2015-11-22 00:00:00 0144 // absl::CivilMonth : 2015-11-01 00:00:00 0145 // absl::CivilYear : 2015-01-01 00:00:00 0146 // 0147 // Each civil-time type performs arithmetic on the field to which it is 0148 // aligned. This means that adding 1 to an absl::CivilDay increments the day 0149 // field (normalizing as necessary), and subtracting 7 from an absl::CivilMonth 0150 // operates on the month field (normalizing as necessary). All arithmetic 0151 // produces a valid civil time. Difference requires two similarly aligned 0152 // civil-time objects and returns the scalar answer in units of the objects' 0153 // alignment. For example, the difference between two absl::CivilHour objects 0154 // will give an answer in units of civil hours. 0155 // 0156 // ALIGNMENT CONVERSION 0157 // 0158 // The alignment of a civil-time object cannot change, but the object may be 0159 // used to construct a new object with a different alignment. This is referred 0160 // to as "realigning". When realigning to a type with the same or more 0161 // precision (e.g., absl::CivilDay -> absl::CivilSecond), the conversion may be 0162 // performed implicitly since no information is lost. However, if information 0163 // could be discarded (e.g., CivilSecond -> CivilDay), the conversion must 0164 // be explicit at the call site. 0165 // 0166 // Examples: 0167 // 0168 // void UseDay(absl::CivilDay day); 0169 // 0170 // absl::CivilSecond cs; 0171 // UseDay(cs); // Won't compile because data may be discarded 0172 // UseDay(absl::CivilDay(cs)); // OK: explicit conversion 0173 // 0174 // absl::CivilDay cd; 0175 // UseDay(cd); // OK: no conversion needed 0176 // 0177 // absl::CivilMonth cm; 0178 // UseDay(cm); // OK: implicit conversion to absl::CivilDay 0179 // 0180 // NORMALIZATION 0181 // 0182 // Normalization takes invalid values and adjusts them to produce valid values. 0183 // Within the civil-time library, integer arguments passed to the Civil* 0184 // constructors may be out-of-range, in which case they are normalized by 0185 // carrying overflow into a field of courser granularity to produce valid 0186 // civil-time objects. This normalization enables natural arithmetic on 0187 // constructor arguments without worrying about the field's range. 0188 // 0189 // Examples: 0190 // 0191 // // Out-of-range; normalized to 2016-11-01 0192 // absl::CivilDay d(2016, 10, 32); 0193 // // Out-of-range, negative: normalized to 2016-10-30T23 0194 // absl::CivilHour h1(2016, 10, 31, -1); 0195 // // Normalization is cumulative: normalized to 2016-10-30T23 0196 // absl::CivilHour h2(2016, 10, 32, -25); 0197 // 0198 // Note: If normalization is undesired, you can signal an error by comparing 0199 // the constructor arguments to the normalized values returned by the YMDHMS 0200 // properties. 0201 // 0202 // COMPARISON 0203 // 0204 // Comparison between civil-time objects considers all six YMDHMS fields, 0205 // regardless of the type's alignment. Comparison between differently aligned 0206 // civil-time types is allowed. 0207 // 0208 // Examples: 0209 // 0210 // absl::CivilDay feb_3(2015, 2, 3); // 2015-02-03 00:00:00 0211 // absl::CivilDay mar_4(2015, 3, 4); // 2015-03-04 00:00:00 0212 // // feb_3 < mar_4 0213 // // absl::CivilYear(feb_3) == absl::CivilYear(mar_4) 0214 // 0215 // absl::CivilSecond feb_3_noon(2015, 2, 3, 12, 0, 0); // 2015-02-03 12:00:00 0216 // // feb_3 < feb_3_noon 0217 // // feb_3 == absl::CivilDay(feb_3_noon) 0218 // 0219 // // Iterates all the days of February 2015. 0220 // for (absl::CivilDay d(2015, 2, 1); d < absl::CivilMonth(2015, 3); ++d) { 0221 // // ... 0222 // } 0223 // 0224 // ARITHMETIC 0225 // 0226 // Civil-time types support natural arithmetic operators such as addition, 0227 // subtraction, and difference. Arithmetic operates on the civil-time field 0228 // indicated in the type's name. Difference operators require arguments with 0229 // the same alignment and return the answer in units of the alignment. 0230 // 0231 // Example: 0232 // 0233 // absl::CivilDay a(2015, 2, 3); 0234 // ++a; // 2015-02-04 00:00:00 0235 // --a; // 2015-02-03 00:00:00 0236 // absl::CivilDay b = a + 1; // 2015-02-04 00:00:00 0237 // absl::CivilDay c = 1 + b; // 2015-02-05 00:00:00 0238 // int n = c - a; // n = 2 (civil days) 0239 // int m = c - absl::CivilMonth(c); // Won't compile: different types. 0240 // 0241 // ACCESSORS 0242 // 0243 // Each civil-time type has accessors for all six of the civil-time fields: 0244 // year, month, day, hour, minute, and second. 0245 // 0246 // civil_year_t year() 0247 // int month() 0248 // int day() 0249 // int hour() 0250 // int minute() 0251 // int second() 0252 // 0253 // Recall that fields inferior to the type's alignment will be set to their 0254 // minimum valid value. 0255 // 0256 // Example: 0257 // 0258 // absl::CivilDay d(2015, 6, 28); 0259 // // d.year() == 2015 0260 // // d.month() == 6 0261 // // d.day() == 28 0262 // // d.hour() == 0 0263 // // d.minute() == 0 0264 // // d.second() == 0 0265 // 0266 // CASE STUDY: Adding a month to January 31. 0267 // 0268 // One of the classic questions that arises when considering a civil time 0269 // library (or a date library or a date/time library) is this: 0270 // "What is the result of adding a month to January 31?" 0271 // This is an interesting question because it is unclear what is meant by a 0272 // "month", and several different answers are possible, depending on context: 0273 // 0274 // 1. March 3 (or 2 if a leap year), if "add a month" means to add a month to 0275 // the current month, and adjust the date to overflow the extra days into 0276 // March. In this case the result of "February 31" would be normalized as 0277 // within the civil-time library. 0278 // 2. February 28 (or 29 if a leap year), if "add a month" means to add a 0279 // month, and adjust the date while holding the resulting month constant. 0280 // In this case, the result of "February 31" would be truncated to the last 0281 // day in February. 0282 // 3. An error. The caller may get some error, an exception, an invalid date 0283 // object, or perhaps return `false`. This may make sense because there is 0284 // no single unambiguously correct answer to the question. 0285 // 0286 // Practically speaking, any answer that is not what the programmer intended 0287 // is the wrong answer. 0288 // 0289 // The Abseil time library avoids this problem by making it impossible to 0290 // ask ambiguous questions. All civil-time objects are aligned to a particular 0291 // civil-field boundary (such as aligned to a year, month, day, hour, minute, 0292 // or second), and arithmetic operates on the field to which the object is 0293 // aligned. This means that in order to "add a month" the object must first be 0294 // aligned to a month boundary, which is equivalent to the first day of that 0295 // month. 0296 // 0297 // Of course, there are ways to compute an answer the question at hand using 0298 // this Abseil time library, but they require the programmer to be explicit 0299 // about the answer they expect. To illustrate, let's see how to compute all 0300 // three of the above possible answers to the question of "Jan 31 plus 1 0301 // month": 0302 // 0303 // Example: 0304 // 0305 // const absl::CivilDay d(2015, 1, 31); 0306 // 0307 // // Answer 1: 0308 // // Add 1 to the month field in the constructor, and rely on normalization. 0309 // const auto normalized = absl::CivilDay(d.year(), d.month() + 1, d.day()); 0310 // // normalized == 2015-03-03 (aka Feb 31) 0311 // 0312 // // Answer 2: 0313 // // Add 1 to month field, capping to the end of next month. 0314 // const auto next_month = absl::CivilMonth(d) + 1; 0315 // const auto last_day_of_next_month = absl::CivilDay(next_month + 1) - 1; 0316 // const auto capped = std::min(normalized, last_day_of_next_month); 0317 // // capped == 2015-02-28 0318 // 0319 // // Answer 3: 0320 // // Signal an error if the normalized answer is not in next month. 0321 // if (absl::CivilMonth(normalized) != next_month) { 0322 // // error, month overflow 0323 // } 0324 // 0325 using CivilSecond = 0326 time_internal::cctz::detail::civil_time<time_internal::second_tag>; 0327 using CivilMinute = 0328 time_internal::cctz::detail::civil_time<time_internal::minute_tag>; 0329 using CivilHour = 0330 time_internal::cctz::detail::civil_time<time_internal::hour_tag>; 0331 using CivilDay = 0332 time_internal::cctz::detail::civil_time<time_internal::day_tag>; 0333 using CivilMonth = 0334 time_internal::cctz::detail::civil_time<time_internal::month_tag>; 0335 using CivilYear = 0336 time_internal::cctz::detail::civil_time<time_internal::year_tag>; 0337 0338 // civil_year_t 0339 // 0340 // Type alias of a civil-time year value. This type is guaranteed to (at least) 0341 // support any year value supported by `time_t`. 0342 // 0343 // Example: 0344 // 0345 // absl::CivilSecond cs = ...; 0346 // absl::civil_year_t y = cs.year(); 0347 // cs = absl::CivilSecond(y, 1, 1, 0, 0, 0); // CivilSecond(CivilYear(cs)) 0348 // 0349 using civil_year_t = time_internal::cctz::year_t; 0350 0351 // civil_diff_t 0352 // 0353 // Type alias of the difference between two civil-time values. 0354 // This type is used to indicate arguments that are not 0355 // normalized (such as parameters to the civil-time constructors), the results 0356 // of civil-time subtraction, or the operand to civil-time addition. 0357 // 0358 // Example: 0359 // 0360 // absl::civil_diff_t n_sec = cs1 - cs2; // cs1 == cs2 + n_sec; 0361 // 0362 using civil_diff_t = time_internal::cctz::diff_t; 0363 0364 // Weekday::monday, Weekday::tuesday, Weekday::wednesday, Weekday::thursday, 0365 // Weekday::friday, Weekday::saturday, Weekday::sunday 0366 // 0367 // The Weekday enum class represents the civil-time concept of a "weekday" with 0368 // members for all days of the week. 0369 // 0370 // absl::Weekday wd = absl::Weekday::thursday; 0371 // 0372 using Weekday = time_internal::cctz::weekday; 0373 0374 // GetWeekday() 0375 // 0376 // Returns the absl::Weekday for the given (realigned) civil-time value. 0377 // 0378 // Example: 0379 // 0380 // absl::CivilDay a(2015, 8, 13); 0381 // absl::Weekday wd = absl::GetWeekday(a); // wd == absl::Weekday::thursday 0382 // 0383 inline Weekday GetWeekday(CivilSecond cs) { 0384 return time_internal::cctz::get_weekday(cs); 0385 } 0386 0387 // NextWeekday() 0388 // PrevWeekday() 0389 // 0390 // Returns the absl::CivilDay that strictly follows or precedes a given 0391 // absl::CivilDay, and that falls on the given absl::Weekday. 0392 // 0393 // Example, given the following month: 0394 // 0395 // August 2015 0396 // Su Mo Tu We Th Fr Sa 0397 // 1 0398 // 2 3 4 5 6 7 8 0399 // 9 10 11 12 13 14 15 0400 // 16 17 18 19 20 21 22 0401 // 23 24 25 26 27 28 29 0402 // 30 31 0403 // 0404 // absl::CivilDay a(2015, 8, 13); 0405 // // absl::GetWeekday(a) == absl::Weekday::thursday 0406 // absl::CivilDay b = absl::NextWeekday(a, absl::Weekday::thursday); 0407 // // b = 2015-08-20 0408 // absl::CivilDay c = absl::PrevWeekday(a, absl::Weekday::thursday); 0409 // // c = 2015-08-06 0410 // 0411 // absl::CivilDay d = ... 0412 // // Gets the following Thursday if d is not already Thursday 0413 // absl::CivilDay thurs1 = absl::NextWeekday(d - 1, absl::Weekday::thursday); 0414 // // Gets the previous Thursday if d is not already Thursday 0415 // absl::CivilDay thurs2 = absl::PrevWeekday(d + 1, absl::Weekday::thursday); 0416 // 0417 inline CivilDay NextWeekday(CivilDay cd, Weekday wd) { 0418 return CivilDay(time_internal::cctz::next_weekday(cd, wd)); 0419 } 0420 inline CivilDay PrevWeekday(CivilDay cd, Weekday wd) { 0421 return CivilDay(time_internal::cctz::prev_weekday(cd, wd)); 0422 } 0423 0424 // GetYearDay() 0425 // 0426 // Returns the day-of-year for the given (realigned) civil-time value. 0427 // 0428 // Example: 0429 // 0430 // absl::CivilDay a(2015, 1, 1); 0431 // int yd_jan_1 = absl::GetYearDay(a); // yd_jan_1 = 1 0432 // absl::CivilDay b(2015, 12, 31); 0433 // int yd_dec_31 = absl::GetYearDay(b); // yd_dec_31 = 365 0434 // 0435 inline int GetYearDay(CivilSecond cs) { 0436 return time_internal::cctz::get_yearday(cs); 0437 } 0438 0439 // FormatCivilTime() 0440 // 0441 // Formats the given civil-time value into a string value of the following 0442 // format: 0443 // 0444 // Type | Format 0445 // --------------------------------- 0446 // CivilSecond | YYYY-MM-DDTHH:MM:SS 0447 // CivilMinute | YYYY-MM-DDTHH:MM 0448 // CivilHour | YYYY-MM-DDTHH 0449 // CivilDay | YYYY-MM-DD 0450 // CivilMonth | YYYY-MM 0451 // CivilYear | YYYY 0452 // 0453 // Example: 0454 // 0455 // absl::CivilDay d = absl::CivilDay(1969, 7, 20); 0456 // std::string day_string = absl::FormatCivilTime(d); // "1969-07-20" 0457 // 0458 std::string FormatCivilTime(CivilSecond c); 0459 std::string FormatCivilTime(CivilMinute c); 0460 std::string FormatCivilTime(CivilHour c); 0461 std::string FormatCivilTime(CivilDay c); 0462 std::string FormatCivilTime(CivilMonth c); 0463 std::string FormatCivilTime(CivilYear c); 0464 0465 // Support for StrFormat(), StrCat(), etc 0466 template <typename Sink> 0467 void AbslStringify(Sink& sink, CivilSecond c) { 0468 sink.Append(FormatCivilTime(c)); 0469 } 0470 template <typename Sink> 0471 void AbslStringify(Sink& sink, CivilMinute c) { 0472 sink.Append(FormatCivilTime(c)); 0473 } 0474 template <typename Sink> 0475 void AbslStringify(Sink& sink, CivilHour c) { 0476 sink.Append(FormatCivilTime(c)); 0477 } 0478 template <typename Sink> 0479 void AbslStringify(Sink& sink, CivilDay c) { 0480 sink.Append(FormatCivilTime(c)); 0481 } 0482 template <typename Sink> 0483 void AbslStringify(Sink& sink, CivilMonth c) { 0484 sink.Append(FormatCivilTime(c)); 0485 } 0486 template <typename Sink> 0487 void AbslStringify(Sink& sink, CivilYear c) { 0488 sink.Append(FormatCivilTime(c)); 0489 } 0490 0491 // absl::ParseCivilTime() 0492 // 0493 // Parses a civil-time value from the specified `absl::string_view` into the 0494 // passed output parameter. Returns `true` upon successful parsing. 0495 // 0496 // The expected form of the input string is as follows: 0497 // 0498 // Type | Format 0499 // --------------------------------- 0500 // CivilSecond | YYYY-MM-DDTHH:MM:SS 0501 // CivilMinute | YYYY-MM-DDTHH:MM 0502 // CivilHour | YYYY-MM-DDTHH 0503 // CivilDay | YYYY-MM-DD 0504 // CivilMonth | YYYY-MM 0505 // CivilYear | YYYY 0506 // 0507 // Example: 0508 // 0509 // absl::CivilDay d; 0510 // bool ok = absl::ParseCivilTime("2018-01-02", &d); // OK 0511 // 0512 // Note that parsing will fail if the string's format does not match the 0513 // expected type exactly. `ParseLenientCivilTime()` below is more lenient. 0514 // 0515 bool ParseCivilTime(absl::string_view s, CivilSecond* c); 0516 bool ParseCivilTime(absl::string_view s, CivilMinute* c); 0517 bool ParseCivilTime(absl::string_view s, CivilHour* c); 0518 bool ParseCivilTime(absl::string_view s, CivilDay* c); 0519 bool ParseCivilTime(absl::string_view s, CivilMonth* c); 0520 bool ParseCivilTime(absl::string_view s, CivilYear* c); 0521 0522 // ParseLenientCivilTime() 0523 // 0524 // Parses any of the formats accepted by `absl::ParseCivilTime()`, but is more 0525 // lenient if the format of the string does not exactly match the associated 0526 // type. 0527 // 0528 // Example: 0529 // 0530 // absl::CivilDay d; 0531 // bool ok = absl::ParseLenientCivilTime("1969-07-20", &d); // OK 0532 // ok = absl::ParseLenientCivilTime("1969-07-20T10", &d); // OK: T10 floored 0533 // ok = absl::ParseLenientCivilTime("1969-07", &d); // OK: day defaults to 1 0534 // 0535 bool ParseLenientCivilTime(absl::string_view s, CivilSecond* c); 0536 bool ParseLenientCivilTime(absl::string_view s, CivilMinute* c); 0537 bool ParseLenientCivilTime(absl::string_view s, CivilHour* c); 0538 bool ParseLenientCivilTime(absl::string_view s, CivilDay* c); 0539 bool ParseLenientCivilTime(absl::string_view s, CivilMonth* c); 0540 bool ParseLenientCivilTime(absl::string_view s, CivilYear* c); 0541 0542 namespace time_internal { // For functions found via ADL on civil-time tags. 0543 0544 // Streaming Operators 0545 // 0546 // Each civil-time type may be sent to an output stream using operator<<(). 0547 // The result matches the string produced by `FormatCivilTime()`. 0548 // 0549 // Example: 0550 // 0551 // absl::CivilDay d = absl::CivilDay(1969, 7, 20); 0552 // std::cout << "Date is: " << d << "\n"; 0553 // 0554 std::ostream& operator<<(std::ostream& os, CivilYear y); 0555 std::ostream& operator<<(std::ostream& os, CivilMonth m); 0556 std::ostream& operator<<(std::ostream& os, CivilDay d); 0557 std::ostream& operator<<(std::ostream& os, CivilHour h); 0558 std::ostream& operator<<(std::ostream& os, CivilMinute m); 0559 std::ostream& operator<<(std::ostream& os, CivilSecond s); 0560 0561 // AbslParseFlag() 0562 // 0563 // Parses the command-line flag string representation `s` into a civil-time 0564 // value. Flags must be specified in a format that is valid for 0565 // `absl::ParseLenientCivilTime()`. 0566 bool AbslParseFlag(absl::string_view s, CivilSecond* c, std::string* error); 0567 bool AbslParseFlag(absl::string_view s, CivilMinute* c, std::string* error); 0568 bool AbslParseFlag(absl::string_view s, CivilHour* c, std::string* error); 0569 bool AbslParseFlag(absl::string_view s, CivilDay* c, std::string* error); 0570 bool AbslParseFlag(absl::string_view s, CivilMonth* c, std::string* error); 0571 bool AbslParseFlag(absl::string_view s, CivilYear* c, std::string* error); 0572 0573 // AbslUnparseFlag() 0574 // 0575 // Unparses a civil-time value into a command-line string representation using 0576 // the format specified by `absl::ParseCivilTime()`. 0577 std::string AbslUnparseFlag(CivilSecond c); 0578 std::string AbslUnparseFlag(CivilMinute c); 0579 std::string AbslUnparseFlag(CivilHour c); 0580 std::string AbslUnparseFlag(CivilDay c); 0581 std::string AbslUnparseFlag(CivilMonth c); 0582 std::string AbslUnparseFlag(CivilYear c); 0583 0584 } // namespace time_internal 0585 0586 ABSL_NAMESPACE_END 0587 } // namespace absl 0588 0589 #endif // ABSL_TIME_CIVIL_TIME_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |