DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
TimeSpan.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "Common.h"
9#include "System/Object.h"
10#include <cstdint>
11
12namespace DotNetDupe {
13 namespace System {
14
20 class TimeSpan : public Object {
21 public:
23 static constexpr int64_t TicksPerMillisecond = 10000;
24
26 static constexpr int64_t TicksPerSecond = TicksPerMillisecond * 1000;
27
29 static constexpr int64_t TicksPerMinute = TicksPerSecond * 60;
30
32 static constexpr int64_t TicksPerHour = TicksPerMinute * 60;
33
35 static constexpr int64_t TicksPerDay = TicksPerHour * 24;
36
38 TimeSpan() : _ticks(0) {}
39
42 TimeSpan(int64_t ticks) : _ticks(ticks) {}
43
46 int64_t GetTicks() const { return _ticks; }
47
50 double GetTotalMilliseconds() const { return (double)_ticks / TicksPerMillisecond; }
51
54 double GetTotalSeconds() const { return (double)_ticks / TicksPerSecond; }
55
58 double GetTotalMinutes() const { return (double)_ticks / TicksPerMinute; }
59
62 double GetTotalHours() const { return (double)_ticks / TicksPerHour; }
63
66 double GetTotalDays() const { return (double)_ticks / TicksPerDay; }
67
71 static TimeSpan FromTicks(int64_t ticks) { return TimeSpan(ticks); }
72
76 static TimeSpan FromMilliseconds(double value) { return TimeSpan((int64_t)(value * TicksPerMillisecond)); }
77
81 static TimeSpan FromSeconds(double value) { return TimeSpan((int64_t)(value * TicksPerSecond)); }
82
86 static TimeSpan FromMinutes(double value) { return TimeSpan((int64_t)(value * TicksPerMinute)); }
87
91 static TimeSpan FromHours(double value) { return TimeSpan((int64_t)(value * TicksPerHour)); }
92
96 static TimeSpan FromDays(double value) { return TimeSpan((int64_t)(value * TicksPerDay)); }
97
99 bool operator==(const TimeSpan& other) const { return _ticks == other._ticks; }
100
102 bool operator!=(const TimeSpan& other) const { return _ticks != other._ticks; }
103
105 bool operator<(const TimeSpan& other) const { return _ticks < other._ticks; }
106
108 bool operator<=(const TimeSpan& other) const { return _ticks <= other._ticks; }
109
111 bool operator>(const TimeSpan& other) const { return _ticks > other._ticks; }
112
114 bool operator>=(const TimeSpan& other) const { return _ticks >= other._ticks; }
115
117 TimeSpan operator+(const TimeSpan& other) const { return TimeSpan(_ticks + other._ticks); }
118
120 TimeSpan operator-(const TimeSpan& other) const { return TimeSpan(_ticks - other._ticks); }
121
122 private:
123 int64_t _ticks;
124 };
125 }
126}
Defines common cross-platform macros, export decorators, and fundamental types.
Base object class for DotNetDupe mirroring .NET System.Object.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
static constexpr int64_t TicksPerHour
The number of ticks in 1 hour.
Definition TimeSpan.h:32
double GetTotalMinutes() const
Gets the value of the current TimeSpan expressed in whole and fractional minutes.
Definition TimeSpan.h:58
static TimeSpan FromSeconds(double value)
Returns a TimeSpan that represents a specified number of seconds.
Definition TimeSpan.h:81
static TimeSpan FromDays(double value)
Returns a TimeSpan that represents a specified number of days.
Definition TimeSpan.h:96
bool operator<(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
Definition TimeSpan.h:105
bool operator>=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater than or equal to another specified TimeSpan.
Definition TimeSpan.h:114
static constexpr int64_t TicksPerSecond
The number of ticks in 1 second.
Definition TimeSpan.h:26
bool operator!=(const TimeSpan &other) const
Indicates whether two TimeSpan instances are not equal.
Definition TimeSpan.h:102
bool operator<=(const TimeSpan &other) const
Indicates whether a specified TimeSpan is less than or equal to another specified TimeSpan.
Definition TimeSpan.h:108
static TimeSpan FromMilliseconds(double value)
Returns a TimeSpan that represents a specified number of milliseconds.
Definition TimeSpan.h:76
double GetTotalSeconds() const
Gets the value of the current TimeSpan expressed in whole and fractional seconds.
Definition TimeSpan.h:54
TimeSpan(int64_t ticks)
Initializes a new instance of TimeSpan to the specified number of ticks.
Definition TimeSpan.h:42
static TimeSpan FromTicks(int64_t ticks)
Returns a TimeSpan that represents a specified number of ticks.
Definition TimeSpan.h:71
TimeSpan operator+(const TimeSpan &other) const
Adds a specified TimeSpan to this instance.
Definition TimeSpan.h:117
bool operator==(const TimeSpan &other) const
Indicates whether two TimeSpan instances are equal.
Definition TimeSpan.h:99
bool operator>(const TimeSpan &other) const
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
Definition TimeSpan.h:111
TimeSpan()
Initializes a new instance of TimeSpan to zero duration.
Definition TimeSpan.h:38
static constexpr int64_t TicksPerDay
The number of ticks in 1 day.
Definition TimeSpan.h:35
static constexpr int64_t TicksPerMillisecond
The number of ticks in 1 millisecond.
Definition TimeSpan.h:23
double GetTotalDays() const
Gets the value of the current TimeSpan expressed in whole and fractional days.
Definition TimeSpan.h:66
static TimeSpan FromMinutes(double value)
Returns a TimeSpan that represents a specified number of minutes.
Definition TimeSpan.h:86
static TimeSpan FromHours(double value)
Returns a TimeSpan that represents a specified number of hours.
Definition TimeSpan.h:91
TimeSpan operator-(const TimeSpan &other) const
Subtracts a specified TimeSpan from this instance.
Definition TimeSpan.h:120
double GetTotalHours() const
Gets the value of the current TimeSpan expressed in whole and fractional hours.
Definition TimeSpan.h:62
double GetTotalMilliseconds() const
Gets the value of the current TimeSpan expressed in whole and fractional milliseconds.
Definition TimeSpan.h:50
static constexpr int64_t TicksPerMinute
The number of ticks in 1 minute.
Definition TimeSpan.h:29
int64_t GetTicks() const
Gets the number of ticks that represent the value of the current TimeSpan structure.
Definition TimeSpan.h:46