Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: net/base/build_time.cc

Issue 8467031: net: make pinning enforcement timeout after ten weeks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/build_time.h"
6
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "base/logging.h"
11 #include "base/time.h"
12
13 namespace net {
14
15 int GetDaysSinceBuild() {
16 // The format of __DATE__ is specified by the ANSI C Standard, section 6.8.8.
17 // It is exactly "Mth DD YYYY".
wtc 2011/11/08 19:43:40 Nit: Mth => Mmm ? Mth seems to suggest that we sh
18 char build_date[] = __DATE__;
19
20 // We can't use strptime because strptime will use the current locale, while
21 // the format of __DATE__ is locale independent.
22 static const char kMonths[12][4] = {
23 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
24 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
25 };
26
27 build_date[3] = 0;
28 build_date[6] = 0;
wtc 2011/11/08 19:43:40 Nit: use '\0' instead of 0 in these two assignment
29 int year = atoi(&build_date[7]);
30 DCHECK_GE(year, 2011);
31 DCHECK_LT(year, 3000);
32
33 int day = atoi(&build_date[4]);
34 DCHECK_GE(day, 1);
35 DCHECK_LT(day, 32);
36 int month;
37
38 for (month = 1; month <= 12; month++) {
39 if (memcmp(build_date, kMonths[month - 1], 3) == 0) {
40 break;
41 }
42 }
43 DCHECK_GE(month, 1);
44 DCHECK_LT(month, 13);
45
46 base::Time::Exploded build_time_exploded;
47 build_time_exploded.year = year;
48 build_time_exploded.month = month;
49 build_time_exploded.day_of_week = 0;
50 build_time_exploded.day_of_month = day;
51 build_time_exploded.hour = 22; // 2PM PST
52 build_time_exploded.minute = 0;
53 build_time_exploded.second = 0;
54 build_time_exploded.millisecond = 0;
55
56 const base::Time build_time =
57 base::Time::FromUTCExploded(build_time_exploded);
58 const base::Time now = base::Time::Now();
59 if (now < build_time) {
60 // System clock is wrong or we built today.
61 return 0;
62 }
63 const base::TimeDelta delta = now - build_time;
64 return delta.InDays();
65 }
66
67 } // namespace net
68
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698