Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

@ -0,0 +1,2 @@
alancutter@chromium.org
jdoerrie@chromium.org

View file

@ -0,0 +1,60 @@
// Copyright 2019 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/util/values/values_util.h"
#include "base/strings/string_number_conversions.h"
namespace util {
base::Value Int64ToValue(int64_t integer) {
return base::Value(base::NumberToString(integer));
}
base::Optional<int64_t> ValueToInt64(const base::Value* value) {
return value ? ValueToInt64(*value) : base::nullopt;
}
base::Optional<int64_t> ValueToInt64(const base::Value& value) {
if (!value.is_string())
return base::nullopt;
int64_t integer;
if (!base::StringToInt64(value.GetString(), &integer))
return base::nullopt;
return integer;
}
base::Value TimeDeltaToValue(base::TimeDelta time_delta) {
return Int64ToValue(time_delta.InMicroseconds());
}
base::Optional<base::TimeDelta> ValueToTimeDelta(const base::Value* value) {
return value ? ValueToTimeDelta(*value) : base::nullopt;
}
base::Optional<base::TimeDelta> ValueToTimeDelta(const base::Value& value) {
base::Optional<int64_t> integer = ValueToInt64(value);
if (!integer)
return base::nullopt;
return base::TimeDelta::FromMicroseconds(*integer);
}
base::Value TimeToValue(base::Time time) {
return TimeDeltaToValue(time.ToDeltaSinceWindowsEpoch());
}
base::Optional<base::Time> ValueToTime(const base::Value* value) {
return value ? ValueToTime(*value) : base::nullopt;
}
base::Optional<base::Time> ValueToTime(const base::Value& value) {
base::Optional<base::TimeDelta> time_delta = ValueToTimeDelta(value);
if (!time_delta)
return base::nullopt;
return base::Time::FromDeltaSinceWindowsEpoch(*time_delta);
}
} // namespace util

View file

@ -0,0 +1,36 @@
// Copyright 2019 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_UTIL_VALUES_VALUES_UTIL_H_
#define BASE_UTIL_VALUES_VALUES_UTIL_H_
#include "base/optional.h"
#include "base/time/time.h"
#include "base/values.h"
namespace util {
// Simple helper functions for converting int64_t, base::TimeDelta and
// base::Time to numeric string base::Values.
// Because base::TimeDelta and base::Time share the same internal representation
// as int64_t they are stored using the exact same numeric string format.
// Stores the int64_t as a string.
base::Value Int64ToValue(int64_t integer);
base::Optional<int64_t> ValueToInt64(const base::Value* value);
base::Optional<int64_t> ValueToInt64(const base::Value& value);
// Converts the TimeDelta to an int64_t of microseconds.
base::Value TimeDeltaToValue(base::TimeDelta time_delta);
base::Optional<base::TimeDelta> ValueToTimeDelta(const base::Value* value);
base::Optional<base::TimeDelta> ValueToTimeDelta(const base::Value& value);
// Converts the Time to a TimeDelta from the Windows epoch.
base::Value TimeToValue(base::Time time);
base::Optional<base::Time> ValueToTime(const base::Value* value);
base::Optional<base::Time> ValueToTime(const base::Value& value);
} // namespace util
#endif // BASE_UTIL_VALUES_VALUES_UTIL_H_