Index: net/base/build_time.cc |
diff --git a/net/base/build_time.cc b/net/base/build_time.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2d6313feb167dcbe8dba97346a21b054e8dfc386 |
--- /dev/null |
+++ b/net/base/build_time.cc |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2011 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 "net/base/build_time.h" |
+ |
+#include <stdlib.h> |
+#include <string.h> |
+ |
+#include "base/logging.h" |
+#include "base/time.h" |
+ |
+namespace net { |
+ |
+int GetDaysSinceBuild() { |
+ // The format of __DATE__ is specified by the ANSI C Standard, section 6.8.8. |
+ // It is exactly "Mth DD YYYY". |
wtc
2011/11/08 19:43:40
Nit: Mth => Mmm ?
Mth seems to suggest that we sh
|
+ char build_date[] = __DATE__; |
+ |
+ // We can't use strptime because strptime will use the current locale, while |
+ // the format of __DATE__ is locale independent. |
+ static const char kMonths[12][4] = { |
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
+ }; |
+ |
+ build_date[3] = 0; |
+ build_date[6] = 0; |
wtc
2011/11/08 19:43:40
Nit: use '\0' instead of 0 in these two assignment
|
+ int year = atoi(&build_date[7]); |
+ DCHECK_GE(year, 2011); |
+ DCHECK_LT(year, 3000); |
+ |
+ int day = atoi(&build_date[4]); |
+ DCHECK_GE(day, 1); |
+ DCHECK_LT(day, 32); |
+ int month; |
+ |
+ for (month = 1; month <= 12; month++) { |
+ if (memcmp(build_date, kMonths[month - 1], 3) == 0) { |
+ break; |
+ } |
+ } |
+ DCHECK_GE(month, 1); |
+ DCHECK_LT(month, 13); |
+ |
+ base::Time::Exploded build_time_exploded; |
+ build_time_exploded.year = year; |
+ build_time_exploded.month = month; |
+ build_time_exploded.day_of_week = 0; |
+ build_time_exploded.day_of_month = day; |
+ build_time_exploded.hour = 22; // 2PM PST |
+ build_time_exploded.minute = 0; |
+ build_time_exploded.second = 0; |
+ build_time_exploded.millisecond = 0; |
+ |
+ const base::Time build_time = |
+ base::Time::FromUTCExploded(build_time_exploded); |
+ const base::Time now = base::Time::Now(); |
+ if (now < build_time) { |
+ // System clock is wrong or we built today. |
+ return 0; |
+ } |
+ const base::TimeDelta delta = now - build_time; |
+ return delta.InDays(); |
+} |
+ |
+} // namespace net |
+ |