Commit 08aa0276 authored by agl@chromium.org's avatar agl@chromium.org

base: export GetBuildTime

A need for the function came up in another context so this change exposes it
from base/.

BUG=none
TEST=base_unittests


Review URL: http://codereview.chromium.org/8510027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109638 0039d316-1c4b-4281-b951-d872f2087c98
parent b9971dc6
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
'bind_unittest.cc', 'bind_unittest.cc',
'bind_unittest.nc', 'bind_unittest.nc',
'bits_unittest.cc', 'bits_unittest.cc',
'build_time_unittest.cc',
'callback_unittest.cc', 'callback_unittest.cc',
'callback_unittest.nc', 'callback_unittest.nc',
'command_line_unittest.cc', 'command_line_unittest.cc',
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
'bind_internal.h', 'bind_internal.h',
'bind_internal_win.h', 'bind_internal_win.h',
'bits.h', 'bits.h',
'build_time.cc',
'build_time.h',
'callback.h', 'callback.h',
'callback_internal.cc', 'callback_internal.cc',
'callback_internal.h', 'callback_internal.h',
......
// 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 "base/build_time.h"
#include "base/logging.h"
#include "base/time.h"
namespace base {
Time GetBuildTime() {
Time integral_build_time;
// The format of __DATE__ and __TIME__ is specified by the ANSI C Standard,
// section 6.8.8.
//
// __DATE__ is exactly "Mmm DD YYYY".
// __TIME__ is exactly "hh:mm:ss".
const char kDateTime[] = __DATE__ " " __TIME__ " PST";
bool result = Time::FromString(kDateTime, &integral_build_time);
DCHECK(result);
return integral_build_time;
}
} // namespace base
// 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.
#ifndef BASE_BUILD_TIME_
#define BASE_BUILD_TIME_
#pragma once
#include "base/base_export.h"
#include "base/time.h"
namespace base {
// GetBuildTime returns the time at which the current binary was built.
//
// This uses the __DATE__ and __TIME__ macros, which don't trigger a rebuild
// when they change. However, official builds will always be rebuilt from
// scratch.
//
// Also, since __TIME__ doesn't include a timezone, this value should only be
// considered accurate to a day.
Time BASE_EXPORT GetBuildTime();
} // namespace base
#endif // BASE_BUILD_TIME_
// 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 "base/build_time.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(BuildTime, DateLooksValid) {
char build_date[] = __DATE__;
EXPECT_EQ(11u, strlen(build_date));
EXPECT_EQ(' ', build_date[3]);
EXPECT_EQ(' ', build_date[6]);
}
TEST(BuildTime, TimeLooksValid) {
char build_time[] = __TIME__;
EXPECT_EQ(8u, strlen(build_time));
EXPECT_EQ(':', build_time[2]);
EXPECT_EQ(':', build_time[5]);
}
TEST(BuildTime, DoesntCrash) {
// Since __DATE__ isn't updated unless one does a clobber build, we can't
// really test the value returned by it, except to check that it doesn't
// crash.
base::GetBuildTime();
}
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/build_time.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/sha1.h" #include "base/sha1.h"
#include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
namespace base { namespace base {
...@@ -153,15 +154,6 @@ void FieldTrial::EnableBenchmarking() { ...@@ -153,15 +154,6 @@ void FieldTrial::EnableBenchmarking() {
FieldTrial::~FieldTrial() {} FieldTrial::~FieldTrial() {}
// static
Time FieldTrial::GetBuildTime() {
Time integral_build_time;
const char* kDateTime = __DATE__ " " __TIME__;
bool result = Time::FromString(kDateTime, &integral_build_time);
DCHECK(result);
return integral_build_time;
}
// static // static
double FieldTrial::HashClientId(const std::string& client_id, double FieldTrial::HashClientId(const std::string& client_id,
const std::string& trial_name) { const std::string& trial_name) {
......
...@@ -184,9 +184,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { ...@@ -184,9 +184,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// Returns the group_name. A winner need not have been chosen. // Returns the group_name. A winner need not have been chosen.
std::string group_name_internal() const { return group_name_; } std::string group_name_internal() const { return group_name_; }
// Get build time.
static Time GetBuildTime();
// Calculates a uniformly-distributed double between [0.0, 1.0) given // Calculates a uniformly-distributed double between [0.0, 1.0) given
// a |client_id| and a |trial_name| (the latter is used as salt to avoid // a |client_id| and a |trial_name| (the latter is used as salt to avoid
// separate one-time randomized trials from all having the same results). // separate one-time randomized trials from all having the same results).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment