-
Notifications
You must be signed in to change notification settings - Fork 0
/
duration.h
executable file
·95 lines (80 loc) · 2.47 KB
/
duration.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef __DURATION_H__
#define __DURATION_H__
// Copyright 2006 Mike Desjardins.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "epochcounter.h"
#include "datetypes.h"
namespace dragonfly {
class Duration : public EpochCounter
{
public:
Duration(const EpochCounter& parent)
{
EpochCounter::ticks(parent.ticks());
EpochCounter::days(parent.days());
}
public:
Duration& operator= (const EpochCounter& parent)
{
EpochCounter::ticks(parent.ticks());
EpochCounter::days(parent.days());
return *this;
}
protected:
Duration(tickcount_t init) { ticks(init); }
public:
const int weeks() const { return EpochCounter::days() / DAYS_PER_WEEK; }
const int days() const { return EpochCounter::days(); }
const int hours() const {
return (EpochCounter::days() * TICKS_PER_DAY + ticks()) / TICKS_PER_HOUR;
}
const int minutes() const {
return (EpochCounter::days() * TICKS_PER_DAY + ticks()) / TICKS_PER_MINUTE;
}
const int seconds() const {
return (EpochCounter::days() * TICKS_PER_DAY + ticks()) / TICKS_PER_SECOND;
}
const int subseconds() const {
return (EpochCounter::days() * TICKS_PER_DAY + ticks()) % TICKS_PER_SECOND;
}
};
//-----------------------------------------------------
class Weeks : public Duration
{
public:
Weeks(int weeks) : Duration(weeks * TICKS_PER_WEEK) {}
};
//-----------------------------------------------------
class Days : public Duration
{
public:
Days(int days) : Duration(days * TICKS_PER_WEEK) {}
};
//-----------------------------------------------------
class Hours : public Duration
{
public:
Hours(int hours) : Duration(hours * TICKS_PER_HOUR) {}
};
//-----------------------------------------------------
class Minutes : public Duration
{
public:
Minutes(int minutes) : Duration(minutes * TICKS_PER_MINUTE) {}
};
//-----------------------------------------------------
class Seconds : public Duration
{
public:
Seconds(int seconds) : Duration(seconds * TICKS_PER_SECOND) {}
};
//-----------------------------------------------------
class SubSeconds : public Duration
{
public:
SubSeconds(int subseconds) : Duration(subseconds) {}
};
} // namespace dragonfly
#endif //__DURATION_H__