aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-24 22:16:48 +0000
committerlloyd <[email protected]>2009-12-24 22:16:48 +0000
commitab35e8266cb93df950c0f93a74f9714d9de40f1c (patch)
tree66ec188b36fcb5557b56635df11cc7a59457276b
parent6e4e7b38b837c5a5141b9dbc3aa4e5450f57865a (diff)
Replace time_t_to_tm with calendar_value which returns a struct representing
the calendar time without tying to a particular format. From the C++0x branch.
-rw-r--r--src/asn1/asn1_tm.cpp16
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp11
-rw-r--r--src/utils/time.cpp15
-rw-r--r--src/utils/time.h15
4 files changed, 37 insertions, 20 deletions
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index c57d1bc73..01d31cfbd 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -27,14 +27,14 @@ X509_Time::X509_Time(const std::string& time_str)
*/
X509_Time::X509_Time(u64bit timer)
{
- std::tm time_info = time_t_to_tm(timer);
-
- year = time_info.tm_year + 1900;
- month = time_info.tm_mon + 1;
- day = time_info.tm_mday;
- hour = time_info.tm_hour;
- minute = time_info.tm_min;
- second = time_info.tm_sec;
+ calendar_point cal = calendar_value(timer);
+
+ year = cal.year;
+ month = cal.month;
+ day = cal.day;
+ hour = cal.hour;
+ minute = cal.minutes;
+ second = cal.seconds;
if(year >= 2050)
tag = GENERALIZED_TIME;
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index ee2ed2ddf..dc38e3296 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -50,14 +50,13 @@ u32bit dec_two_digit(byte b1, byte b2)
/*
* Create an EAC_Time
*/
-EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t)
- :tag(t)
+EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) : tag(t)
{
- std::tm time_info = time_t_to_tm(timer);
+ calendar_point cal = calendar_value(timer);
- year = time_info.tm_year + 1900;
- month = time_info.tm_mon + 1;
- day = time_info.tm_mday;
+ year = cal.year;
+ month = cal.month;
+ day = cal.day;
}
/*
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 2de992c9d..fe4521706 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -76,13 +76,18 @@ u64bit system_time()
}
/*
-* Convert a time_t to a struct tm
+* Convert a time_point to a calendar_point
*/
-std::tm time_t_to_tm(u64bit timer)
+calendar_point calendar_value(u64bit a_time_t)
{
- std::time_t time_val = static_cast<std::time_t>(timer);
-
- return do_gmtime(time_val);
+ std::tm tm = do_gmtime(static_cast<std::time_t>(a_time_t));
+
+ return calendar_point(tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday,
+ tm.tm_hour,
+ tm.tm_min,
+ tm.tm_sec);
}
u64bit get_nanoseconds_clock()
diff --git a/src/utils/time.h b/src/utils/time.h
index c7f459096..05fc6c651 100644
--- a/src/utils/time.h
+++ b/src/utils/time.h
@@ -13,12 +13,25 @@
namespace Botan {
+struct BOTAN_DLL calendar_point
+ {
+ u32bit year;
+ byte month;
+ byte day;
+ byte hour;
+ byte minutes;
+ byte seconds;
+
+ calendar_point(u32bit y, byte mon, byte d, byte h, byte min, byte sec) :
+ year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
+ };
+
/*
* Time Access/Conversion Functions
*/
BOTAN_DLL u64bit system_time();
-BOTAN_DLL std::tm time_t_to_tm(u64bit);
+BOTAN_DLL calendar_point calendar_value(u64bit a_time_t);
/**
@return nanoseconds resolution timestamp, unknown epoch