susumu.yata
null+****@clear*****
Thu Feb 28 10:31:24 JST 2013
susumu.yata 2013-02-28 10:31:24 +0900 (Thu, 28 Feb 2013) New Revision: f3fbe0b5f9cc2f05a1dbe798a3f49c311f70b5c7 https://github.com/groonga/grnxx/commit/f3fbe0b5f9cc2f05a1dbe798a3f49c311f70b5c7 Log: Add grnxx::BrokenDownTime. Added files: lib/broken_down_time.cpp lib/broken_down_time.hpp Modified files: lib/Makefile.am lib/time.hpp Modified: lib/Makefile.am (+2 -0) =================================================================== --- lib/Makefile.am 2013-02-28 10:10:37 +0900 (1ea106f) +++ lib/Makefile.am 2013-02-28 10:31:24 +0900 (477ff28) @@ -12,6 +12,7 @@ libgrnxx_la_LDFLAGS = @AM_LTLDFLAGS@ libgrnxx_la_SOURCES = \ backtrace.cpp \ + broken_down_time.cpp \ duration.cpp \ error.cpp \ grnxx.cpp \ @@ -30,6 +31,7 @@ libgrnxx_includedir = ${includedir}/grnxx libgrnxx_include_HEADERS = \ backtrace.hpp \ basic.hpp \ + broken_down_time.hpp \ duration.hpp \ error.hpp \ exception.hpp \ Added: lib/broken_down_time.cpp (+48 -0) 100644 =================================================================== --- /dev/null +++ lib/broken_down_time.cpp 2013-02-28 10:31:24 +0900 (a5c4fa2) @@ -0,0 +1,48 @@ +/* + Copyright (C) 2013 Brazil, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "broken_down_time.hpp" + +#include <iostream> + +#include "string_format.hpp" + +namespace grnxx { + +StringBuilder &BrokenDownTime::write_to(StringBuilder &builder) const { + if (!builder) { + return builder; + } + + builder << (1900 + year) << '-' + << StringFormat::align_right(mon + 1, 2, '0') << '-' + << StringFormat::align_right(mday, 2, '0') << ' ' + << StringFormat::align_right(hour, 2, '0') << ':' + << StringFormat::align_right(min, 2, '0') << ':' + << StringFormat::align_right(sec, 2, '0') << '.' + << StringFormat::align_right(usec, 6, '0'); + return builder; +} + +std::ostream &operator<<(std::ostream &stream, const BrokenDownTime &time) { + char buf[32]; + StringBuilder builder(buf); + builder << time; + return stream.write(builder.c_str(), builder.length()); +} + +} // namespace grnxx Added: lib/broken_down_time.hpp (+50 -0) 100644 =================================================================== --- /dev/null +++ lib/broken_down_time.hpp 2013-02-28 10:31:24 +0900 (43c7295) @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 Brazil, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef GRNXX_BROKEN_DOWN_TIME_HPP +#define GRNXX_BROKEN_DOWN_TIME_HPP + +#include "basic.hpp" +#include "string_builder.hpp" + +namespace grnxx { + +struct BrokenDownTime { + int usec; // Microseconds. + int sec; // Seconds. + int min; // Minutes. + int hour; // Hours. + int mday; // Day of the month. + int mon; // Month. + int year; // Year. + int wday; // Day of the week. + int yday; // Day in the year. + int isdst; // Daylight saving time. + + StringBuilder &write_to(StringBuilder &builder) const; +}; + +inline StringBuilder &operator<<(StringBuilder &builder, + const BrokenDownTime &time) { + return time.write_to(builder); +} + +std::ostream &operator<<(std::ostream &stream, const BrokenDownTime &time); + +} // namespace grnxx + +#endif // GRNXX_BROKEN_DOWN_TIME_HPP Modified: lib/time.hpp (+4 -6) =================================================================== --- lib/time.hpp 2013-02-28 10:10:37 +0900 (3e6d767) +++ lib/time.hpp 2013-02-28 10:31:24 +0900 (849bf12) @@ -19,13 +19,11 @@ #define GRNXX_TIME_HPP #include "basic.hpp" +#include "broken_down_time.hpp" #include "duration.hpp" namespace grnxx { -// TODO -class DateTime; - // Time in microseconds since the Unix epoch (1970-01-01 00:00:00 UTC). // 64-bit tick count (usec) is used. class Time { @@ -44,11 +42,11 @@ class Time { return Time(std::numeric_limits<int64_t>::max()); } - // TODO + // TODO: To be implemented. // Transform tick count to broken-down time (UTC). - DateTime universal_time() const; + BrokenDownTime universal_time() const; // Transform tick count to broken-down time (local). - DateTime local_time() const; + BrokenDownTime local_time() const; // Return the tick count. constexpr int64_t count() { -------------- next part -------------- HTML����������������������������...Download