Index: base/value_conversions.cc |
diff --git a/base/value_conversions.cc b/base/value_conversions.cc |
index f4957a4610c8316245dd1a6df7511417b513f879..caf9d724ef94d159ed03257422b8daf7ff2a38b9 100644 |
--- a/base/value_conversions.cc |
+++ b/base/value_conversions.cc |
@@ -1,10 +1,12 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
#include "base/value_conversions.h" |
#include "base/file_path.h" |
+#include "base/string_number_conversions.h" |
+#include "base/time.h" |
#include "base/values.h" |
namespace base { |
@@ -24,4 +26,21 @@ bool GetValueAsFilePath(const Value& value, FilePath* file_path) { |
return true; |
} |
+// |Value| does not support 64-bit integers, and doubles do not have enough |
+// precision, so we store the 64-bit time value as a string instead. |
+StringValue* CreateTimeValue(const Time& time) { |
+ std::string string_value = base::Int64ToString(time.ToInternalValue()); |
+ return new StringValue(string_value); |
+} |
+ |
+bool GetValueAsTime(const Value& value, Time* time) { |
+ std::string str; |
+ int64 int_value; |
+ if (!value.GetAsString(&str) || !base::StringToInt64(str, &int_value)) |
+ return false; |
+ if (time) |
+ *time = base::Time::FromInternalValue(int_value); |
+ return true; |
+} |
+ |
} // namespace base |