From 7e21716af4500f353f8ac62fcf5d461db12c967f Mon Sep 17 00:00:00 2001 From: Myun2 Date: Tue, 1 May 2012 02:15:41 +0900 Subject: [PATCH] =?utf8?q?unixtime.hpp:=20to=5Fstring()=20=E6=9A=AB?= =?utf8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/time/unixtime.hpp | 14 ++++++++++++-- roast/test/roast_test_3rd/time_test.cpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/roast/include/roast/time/unixtime.hpp b/roast/include/roast/time/unixtime.hpp index 4467c2e0..67a0a0f1 100644 --- a/roast/include/roast/time/unixtime.hpp +++ b/roast/include/roast/time/unixtime.hpp @@ -6,6 +6,7 @@ #define __SFJP_ROAST__time__unixtime_HPP__ #include +#include namespace roast { @@ -22,18 +23,27 @@ namespace roast class unix_time { protected: + // UNIX Time Value unix_time_type m_time; public: + // Constructor unix_time(){ m_time = get_unix_time_now(); } unix_time(const unix_time_type& tm) : m_time(tm) {} + // Accessors unix_time_type get() const { return m_time; } unix_time_type get_time() const { return m_time; } unix_time_type to_time() const { return m_time; } void set(const unix_time_type& tm) { m_time = tm; } void set_time(const unix_time_type& tm) { m_time = tm; } - - operator unix_time_type() { return m_time; } + + // To String + ::std::string to_string() const { + return ::ctime(&m_time); + } + + // Operators + operator unix_time_type() const { return m_time; } }; typedef unix_time unixtime; diff --git a/roast/test/roast_test_3rd/time_test.cpp b/roast/test/roast_test_3rd/time_test.cpp index ecfc52bc..ada4fe6c 100644 --- a/roast/test/roast_test_3rd/time_test.cpp +++ b/roast/test/roast_test_3rd/time_test.cpp @@ -7,6 +7,7 @@ int main() { unixtime ut; printf("%d\n", ut.to_time()); + printf("%s\n", ut.to_string().c_str()); return 0; } -- 2.11.0