类图
类Clock
- 接口类
1 |
virtual Time Now() const = 0; |
类DefaultClock
- Clock的派生类
1 2 3 4 5 6 7 8 9 |
Time DefaultClock::Now() const { return Time::Now(); } // static DefaultClock* DefaultClock::GetInstance() { static base::NoDestructor<DefaultClock> instance; return instance.get(); } |
类TickClock
- 接口类
1 |
virtual TimeTicks NowTicks() const = 0; |
类DefaultTickClock
- TickClock的派生类
1 2 3 4 5 6 7 8 9 10 11 |
DefaultTickClock::~DefaultTickClock() = default; TimeTicks DefaultTickClock::NowTicks() const { return TimeTicks::Now(); } // static const DefaultTickClock* DefaultTickClock::GetInstance() { static const base::NoDestructor<DefaultTickClock> default_tick_clock; return default_tick_clock.get(); } |
time_to_iso8601.h
- namespace base
1 2 3 4 5 6 7 |
std::string TimeToISO8601(const Time& t) { Time::Exploded exploded; t.UTCExplode(&exploded); return StringPrintf("%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, exploded.millisecond); } |
类TimeDelta
1 2 3 4 5 6 7 8 9 10 11 |
static constexpr TimeDelta FromDays(int days); static constexpr TimeDelta FromHours(int hours); static constexpr TimeDelta FromMinutes(int minutes); static constexpr TimeDelta FromSecondsD(double secs); static constexpr TimeDelta FromSeconds(int64_t secs); static constexpr TimeDelta FromMillisecondsD(double ms); static constexpr TimeDelta FromMilliseconds(int64_t ms); static constexpr TimeDelta FromMicrosecondsD(double us); static constexpr TimeDelta FromMicroseconds(int64_t us); static constexpr TimeDelta FromNanosecondsD(double ns); static constexpr TimeDelta FromNanoseconds(int64_t ns); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
static TimeDelta FromQPCValue(LONGLONG qpc_value); // TODO(crbug.com/989694): Avoid base::TimeDelta factory functions // based on absolute time static TimeDelta FromFileTime(FILETIME ft); static TimeDelta FromWinrtDateTime(ABI::Windows::Foundation::DateTime dt); // Converts a frequency in Hertz (cycles per second) into a period. static constexpr TimeDelta FromHz(double frequency); static Optional<TimeDelta> FromString(StringPiece duration_string); static constexpr TimeDelta FromInternalValue(int64_t delta) { return TimeDelta(delta); } |
1 2 3 4 5 6 7 |
constexpr int64_t ToInternalValue() const { return delta_; } constexpr double ToDouble() const { if (!is_inf()) return static_cast<double>(delta_); return (delta_ < 0) ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//时间转换 int InDays() const; int InDaysFloored() const; constexpr int InHours() const; constexpr int InMinutes() const; constexpr double InSecondsF() const; constexpr int64_t InSeconds() const; double InMillisecondsF() const; int64_t InMilliseconds() const; int64_t InMillisecondsRoundedUp() const; constexpr int64_t InMicroseconds() const { return delta_; } double InMicrosecondsF() const; constexpr int64_t InNanoseconds() const; |
1 2 3 4 |
//取整 TimeDelta CeilToMultiple(TimeDelta interval) const; TimeDelta FloorToMultiple(TimeDelta interval) const; TimeDelta RoundToMultiple(TimeDelta interval) const; |
类TimeBase
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//时间转换用到的定义 static constexpr int64_t kHoursPerDay = 24; static constexpr int64_t kSecondsPerMinute = 60; static constexpr int64_t kMinutesPerHour = 60; static constexpr int64_t kSecondsPerHour = kSecondsPerMinute * kMinutesPerHour; static constexpr int64_t kMillisecondsPerSecond = 1000; static constexpr int64_t kMillisecondsPerDay = kMillisecondsPerSecond * kSecondsPerHour * kHoursPerDay; static constexpr int64_t kMicrosecondsPerMillisecond = 1000; static constexpr int64_t kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * kMillisecondsPerSecond; static constexpr int64_t kMicrosecondsPerMinute = kMicrosecondsPerSecond * kSecondsPerMinute; static constexpr int64_t kMicrosecondsPerHour = kMicrosecondsPerMinute * kMinutesPerHour; static constexpr int64_t kMicrosecondsPerDay = kMicrosecondsPerHour * kHoursPerDay; static constexpr int64_t kMicrosecondsPerWeek = kMicrosecondsPerDay * 7; static constexpr int64_t kNanosecondsPerMicrosecond = 1000; static constexpr int64_t kNanosecondsPerSecond = kNanosecondsPerMicrosecond * kMicrosecondsPerSecond; |
1 2 |
constexpr int64_t ToInternalValue() const { return us_; } |
类Time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
static Time Now(); static Time NowFromSystemTime(); // Converts to/from time_t in UTC and a Time class. static Time FromTimeT(time_t tt); time_t ToTimeT() const; static Time FromDoubleT(double dt); double ToDoubleT() const; static Time FromJsTime(double ms_since_epoch); double ToJsTime() const; double ToJsTimeIgnoringNull() const; static Time FromJavaTime(int64_t ms_since_epoch); int64_t ToJavaTime() const; static bool FromString(const char* time_string, Time* parsed_time) WARN_UNUSED_RESULT { return FromStringInternal(time_string, true, parsed_time); } static bool FromUTCString(const char* time_string, Time* parsed_time) WARN_UNUSED_RESULT { return FromStringInternal(time_string, false, parsed_time); } static constexpr Time FromInternalValue(int64_t us) { return Time(us); } static bool FromStringInternal(const char* time_string, bool is_local, Time* parsed_time) WARN_UNUSED_RESULT; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
/ static constexpr TimeDelta TimeDelta::FromDays(int days) { return (days == std::numeric_limits<int>::max()) ? Max() : TimeDelta(days * Time::kMicrosecondsPerDay); } // static constexpr TimeDelta TimeDelta::FromHours(int hours) { return (hours == std::numeric_limits<int>::max()) ? Max() : TimeDelta(hours * Time::kMicrosecondsPerHour); } // static constexpr TimeDelta TimeDelta::FromMinutes(int minutes) { return (minutes == std::numeric_limits<int>::max()) ? Max() : TimeDelta(minutes * Time::kMicrosecondsPerMinute); } // static constexpr TimeDelta TimeDelta::FromSecondsD(double secs) { return TimeDelta( saturated_cast<int64_t>(secs * Time::kMicrosecondsPerSecond)); } // static constexpr TimeDelta TimeDelta::FromSeconds(int64_t secs) { return TimeDelta(int64_t{base::ClampMul(secs, Time::kMicrosecondsPerSecond)}); } // static constexpr TimeDelta TimeDelta::FromMillisecondsD(double ms) { return TimeDelta( saturated_cast<int64_t>(ms * Time::kMicrosecondsPerMillisecond)); } // static constexpr TimeDelta TimeDelta::FromMilliseconds(int64_t ms) { return TimeDelta( int64_t{base::ClampMul(ms, Time::kMicrosecondsPerMillisecond)}); } // static constexpr TimeDelta TimeDelta::FromMicrosecondsD(double us) { return TimeDelta(saturated_cast<int64_t>(us)); } // static constexpr TimeDelta TimeDelta::FromMicroseconds(int64_t us) { return TimeDelta(us); } // static constexpr TimeDelta TimeDelta::FromNanosecondsD(double ns) { return TimeDelta( saturated_cast<int64_t>(ns / Time::kNanosecondsPerMicrosecond)); } // static constexpr TimeDelta TimeDelta::FromNanoseconds(int64_t ns) { return TimeDelta(ns / Time::kNanosecondsPerMicrosecond); } // static constexpr TimeDelta TimeDelta::FromHz(double frequency) { return FromSeconds(1) / frequency; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ Cef:介绍06/29
- ♥ Base_file05/27
- ♥ Chromium:学习,框架,一09/02
- ♥ Chromium:智能指针部分07/28
- ♥ Base_hash05/25
- ♥ cef:任务、IPC、网络相关04/30