OpenShot Library | OpenShotAudio 0.2.2
juce_RelativeTime.h
1
2/** @weakgroup juce_core-time
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/** A relative measure of time.
32
33 The time is stored as a number of seconds, at double-precision floating
34 point accuracy, and may be positive or negative.
35
36 If you need an absolute time, (i.e. a date + time), see the Time class.
37
38 @tags{Core}
39*/
41{
42public:
43 //==============================================================================
44 /** Creates a RelativeTime.
45
46 @param seconds the number of seconds, which may be +ve or -ve.
47 @see milliseconds, minutes, hours, days, weeks
48 */
49 explicit RelativeTime (double seconds = 0.0) noexcept;
50
51 /** Copies another relative time. */
52 RelativeTime (const RelativeTime& other) noexcept;
53
54 /** Copies another relative time. */
55 RelativeTime& operator= (const RelativeTime& other) noexcept;
56
57 /** Destructor. */
58 ~RelativeTime() noexcept;
59
60 //==============================================================================
61 /** Creates a new RelativeTime object representing a number of milliseconds.
62 @see seconds, minutes, hours, days, weeks
63 */
64 static RelativeTime milliseconds (int milliseconds) noexcept;
65
66 /** Creates a new RelativeTime object representing a number of milliseconds.
67 @see seconds, minutes, hours, days, weeks
68 */
69 static RelativeTime milliseconds (int64 milliseconds) noexcept;
70
71 /** Creates a new RelativeTime object representing a number of seconds.
72 @see milliseconds, minutes, hours, days, weeks
73 */
74 static RelativeTime seconds (double seconds) noexcept;
75
76 /** Creates a new RelativeTime object representing a number of minutes.
77 @see milliseconds, hours, days, weeks
78 */
79 static RelativeTime minutes (double numberOfMinutes) noexcept;
80
81 /** Creates a new RelativeTime object representing a number of hours.
82 @see milliseconds, minutes, days, weeks
83 */
84 static RelativeTime hours (double numberOfHours) noexcept;
85
86 /** Creates a new RelativeTime object representing a number of days.
87 @see milliseconds, minutes, hours, weeks
88 */
89 static RelativeTime days (double numberOfDays) noexcept;
90
91 /** Creates a new RelativeTime object representing a number of weeks.
92 @see milliseconds, minutes, hours, days
93 */
94 static RelativeTime weeks (double numberOfWeeks) noexcept;
95
96 //==============================================================================
97 /** Returns the number of milliseconds this time represents.
98 @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
99 */
100 int64 inMilliseconds() const noexcept;
101
102 /** Returns the number of seconds this time represents.
103 @see inMilliseconds, inMinutes, inHours, inDays, inWeeks
104 */
105 double inSeconds() const noexcept { return numSeconds; }
106
107 /** Returns the number of minutes this time represents.
108 @see inMilliseconds, inSeconds, inHours, inDays, inWeeks
109 */
110 double inMinutes() const noexcept;
111
112 /** Returns the number of hours this time represents.
113 @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks
114 */
115 double inHours() const noexcept;
116
117 /** Returns the number of days this time represents.
118 @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks
119 */
120 double inDays() const noexcept;
121
122 /** Returns the number of weeks this time represents.
123 @see inMilliseconds, inSeconds, inMinutes, inHours, inDays
124 */
125 double inWeeks() const noexcept;
126
127 /** Returns a readable textual description of the time.
128
129 The exact format of the string returned will depend on
130 the magnitude of the time - e.g.
131
132 "1 min 4 secs", "1 hr 45 mins", "2 weeks 5 days", "140 ms"
133
134 so that only the two most significant units are printed.
135
136 The returnValueForZeroTime value is the result that is returned if the
137 length is zero. Depending on your application you might want to use this
138 to return something more relevant like "empty" or "0 secs", etc.
139
140 @see inMilliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
141 */
142 String getDescription (const String& returnValueForZeroTime = "0") const;
143
144 //==============================================================================
145 /** This returns a string that roughly describes how long ago this time was, which
146 can be handy for showing ages of files, etc.
147 This will only attempt to be accurate to within the nearest order of magnitude
148 so returns strings such as "5 years", "2 weeks", "< 1 minute", "< 1 sec" etc.
149 */
150 String getApproximateDescription() const;
151
152 //==============================================================================
153 /** Adds another RelativeTime to this one. */
154 RelativeTime operator+= (RelativeTime timeToAdd) noexcept;
155 /** Subtracts another RelativeTime from this one. */
156 RelativeTime operator-= (RelativeTime timeToSubtract) noexcept;
157
158 /** Adds a number of seconds to this time. */
159 RelativeTime operator+= (double secondsToAdd) noexcept;
160 /** Subtracts a number of seconds from this time. */
161 RelativeTime operator-= (double secondsToSubtract) noexcept;
162
163private:
164 //==============================================================================
165 double numSeconds;
166};
167
168//==============================================================================
169/** Compares two RelativeTimes. */
170JUCE_API bool JUCE_CALLTYPE operator== (RelativeTime t1, RelativeTime t2) noexcept;
171/** Compares two RelativeTimes. */
172JUCE_API bool JUCE_CALLTYPE operator!= (RelativeTime t1, RelativeTime t2) noexcept;
173/** Compares two RelativeTimes. */
174JUCE_API bool JUCE_CALLTYPE operator> (RelativeTime t1, RelativeTime t2) noexcept;
175/** Compares two RelativeTimes. */
176JUCE_API bool JUCE_CALLTYPE operator< (RelativeTime t1, RelativeTime t2) noexcept;
177/** Compares two RelativeTimes. */
178JUCE_API bool JUCE_CALLTYPE operator>= (RelativeTime t1, RelativeTime t2) noexcept;
179/** Compares two RelativeTimes. */
180JUCE_API bool JUCE_CALLTYPE operator<= (RelativeTime t1, RelativeTime t2) noexcept;
181
182//==============================================================================
183/** Adds two RelativeTimes together. */
184JUCE_API RelativeTime JUCE_CALLTYPE operator+ (RelativeTime t1, RelativeTime t2) noexcept;
185/** Subtracts two RelativeTimes. */
186JUCE_API RelativeTime JUCE_CALLTYPE operator- (RelativeTime t1, RelativeTime t2) noexcept;
187
188} // namespace juce
189
190/** @}*/
A relative measure of time.
double inSeconds() const noexcept
Returns the number of seconds this time represents.
The JUCE String class!
Definition: juce_String.h:43
#define JUCE_API
This macro is added to all JUCE public class declarations.