civil_time_detail.cc
Go to the documentation of this file.
00001 // Copyright 2016 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //   https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 //   Unless required by applicable law or agreed to in writing, software
00010 //   distributed under the License is distributed on an "AS IS" BASIS,
00011 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 //   See the License for the specific language governing permissions and
00013 //   limitations under the License.
00014 
00015 #include "absl/time/internal/cctz/include/cctz/civil_time_detail.h"
00016 
00017 #include <iomanip>
00018 #include <ostream>
00019 #include <sstream>
00020 
00021 namespace absl {
00022 namespace time_internal {
00023 namespace cctz {
00024 namespace detail {
00025 
00026 // Output stream operators output a format matching YYYY-MM-DDThh:mm:ss,
00027 // while omitting fields inferior to the type's alignment. For example,
00028 // civil_day is formatted only as YYYY-MM-DD.
00029 std::ostream& operator<<(std::ostream& os, const civil_year& y) {
00030   std::stringstream ss;
00031   ss << y.year();  // No padding.
00032   return os << ss.str();
00033 }
00034 std::ostream& operator<<(std::ostream& os, const civil_month& m) {
00035   std::stringstream ss;
00036   ss << civil_year(m) << '-';
00037   ss << std::setfill('0') << std::setw(2) << m.month();
00038   return os << ss.str();
00039 }
00040 std::ostream& operator<<(std::ostream& os, const civil_day& d) {
00041   std::stringstream ss;
00042   ss << civil_month(d) << '-';
00043   ss << std::setfill('0') << std::setw(2) << d.day();
00044   return os << ss.str();
00045 }
00046 std::ostream& operator<<(std::ostream& os, const civil_hour& h) {
00047   std::stringstream ss;
00048   ss << civil_day(h) << 'T';
00049   ss << std::setfill('0') << std::setw(2) << h.hour();
00050   return os << ss.str();
00051 }
00052 std::ostream& operator<<(std::ostream& os, const civil_minute& m) {
00053   std::stringstream ss;
00054   ss << civil_hour(m) << ':';
00055   ss << std::setfill('0') << std::setw(2) << m.minute();
00056   return os << ss.str();
00057 }
00058 std::ostream& operator<<(std::ostream& os, const civil_second& s) {
00059   std::stringstream ss;
00060   ss << civil_minute(s) << ':';
00061   ss << std::setfill('0') << std::setw(2) << s.second();
00062   return os << ss.str();
00063 }
00064 
00066 
00067 std::ostream& operator<<(std::ostream& os, weekday wd) {
00068   switch (wd) {
00069     case weekday::monday:
00070       return os << "Monday";
00071     case weekday::tuesday:
00072       return os << "Tuesday";
00073     case weekday::wednesday:
00074       return os << "Wednesday";
00075     case weekday::thursday:
00076       return os << "Thursday";
00077     case weekday::friday:
00078       return os << "Friday";
00079     case weekday::saturday:
00080       return os << "Saturday";
00081     case weekday::sunday:
00082       return os << "Sunday";
00083   }
00084   return os;  // Should never get here, but -Wreturn-type may warn without this.
00085 }
00086 
00087 }  // namespace detail
00088 }  // namespace cctz
00089 }  // namespace time_internal
00090 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14