Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kTimeSpan.h
Go to the documentation of this file.
1
10 #ifndef K_API_TIME_SPAN_H
11 #define K_API_TIME_SPAN_H
12
13 #include <kApi/kApiDef.h>
14 #include <kApi/Data/kMath.h>
15
22 typedef k32s kTimeSpanFormat;
23
25 #define kTIME_SPAN_FORMAT_NULL (0)
26 #define kTIME_SPAN_FORMAT_PARTS_FULL (1)
27 #define kTIME_SPAN_FORMAT_PARTS_SIMPLE (2)
28 #define kTIME_SPAN_FORMAT_HMS_FULL (3)
29 #define kTIME_SPAN_FORMAT_HMS_SIMPLE (4)
30
60 typedef k64s kTimeSpan;
61
62 #include <kApi/Utils/kTimeSpan.x.h>
63
75 kInlineFx(kTimeSpan) kTimeSpan_FromParts(k32s daysPart, k32s hoursPart, k32s minutesPart, k32s secondsPart, k32s microsecondsPart)
76 {
77 return (((daysPart*24LL + hoursPart)*60LL + minutesPart)*60LL + secondsPart)*1000000LL + microsecondsPart;
78 }
79
92 kFx(kStatus) kTimeSpan_Parts(kTimeSpan span, k32s* daysPart, k32s* hoursPart, k32s* minutesPart, k32s* secondsPart, k32s* microsecondsPart);
93
101 kInlineFx(k32s) kTimeSpan_DaysPart(kTimeSpan span)
102 {
103 return (k32s) (span / (24LL * 60LL * 60LL * 1000000LL));
104 }
105
113 kInlineFx(k32s) kTimeSpan_HoursPart(kTimeSpan span)
114 {
115 return (k32s) ((span / (60LL * 60LL * 1000000LL)) % 24LL);
116 }
117
125 kInlineFx(k32s) kTimeSpan_MinutesPart(kTimeSpan span)
126 {
127 return (k32s) ((span / (60LL * 1000000LL)) % 60LL);
128 }
129
137 kInlineFx(k32s) kTimeSpan_SecondsPart(kTimeSpan span)
138 {
139 return (k32s) ((span / 1000000LL) % 60LL);
140 }
141
149 kInlineFx(k32s) kTimeSpan_MicrosecondsPart(kTimeSpan span)
150 {
151 return (k32s) (span % 1000000LL);
152 }
153
161 kInlineFx(kTimeSpan) kTimeSpan_FromDays64s(k64s days)
162 {
163 return days * 24LL * 60LL * 60LL * 1000000LL;
164 }
165
173 kInlineFx(kTimeSpan) kTimeSpan_FromDays64f(k64f days)
174 {
175 return (kTimeSpan) kMath_Round64s_(days * 24.0 * 60.0 * 60.0 * 1000000.0);
176 }
177
185 kInlineFx(kTimeSpan) kTimeSpan_FromHours64s(k64s hours)
186 {
187 return hours * 60LL * 60LL * 1000000LL;
188 }
189
197 kInlineFx(kTimeSpan) kTimeSpan_FromHours64f(k64f hours)
198 {
199 return (kTimeSpan) kMath_Round64s_(hours * 60.0 * 60.0 * 1000000.0);
200 }
201
209 kInlineFx(kTimeSpan) kTimeSpan_FromMinutes64s(k64s minutes)
210 {
211 return minutes * 60LL * 1000000LL;
212 }
213
221 kInlineFx(kTimeSpan) kTimeSpan_FromMinutes64f(k64f minutes)
222 {
223 return (kTimeSpan) kMath_Round64s_(minutes * 60.0 * 1000000.0);
224 }
225
233 kInlineFx(kTimeSpan) kTimeSpan_FromSeconds64s(k64s seconds)
234 {
235 return seconds * 1000000LL;
236 }
237
245 kInlineFx(kTimeSpan) kTimeSpan_FromSeconds64f(k64f seconds)
246 {
247 return (kTimeSpan) kMath_Round64s_(seconds * 1000000.0);
248 }
249
257 kInlineFx(kTimeSpan) kTimeSpan_FromMilliseconds64s(k64s milliseconds)
258 {
259 return milliseconds * 1000LL;
260 }
261
269 kInlineFx(kTimeSpan) kTimeSpan_FromMilliseconds64f(k64f milliseconds)
270 {
271 return (kTimeSpan) kMath_Round64s_(milliseconds * 1000LL);
272 }
273
281 kInlineFx(kTimeSpan) kTimeSpan_FromMicroseconds64s(k64s microseconds)
282 {
283 return microseconds;
284 }
285
293 kInlineFx(kTimeSpan) kTimeSpan_FromMicroseconds64f(k64f microseconds)
294 {
295 return (kTimeSpan) kMath_Round64s_(microseconds);
296 }
297
305 kInlineFx(k64s) kTimeSpan_ToDays64s(kTimeSpan span)
306 {
307 return span / (24LL * 60LL * 60LL * 1000000LL);
308 }
309
317 kInlineFx(k64f) kTimeSpan_ToDays64f(kTimeSpan span)
318 {
319 return (k64f)span / (24.0 * 60.0 * 60.0 * 1000000.0);
320 }
321
329 kInlineFx(k64s) kTimeSpan_ToHours64s(kTimeSpan span)
330 {
331 return span / (60LL * 60LL * 1000000LL);
332 }
333
341 kInlineFx(k64f) kTimeSpan_ToHours64f(kTimeSpan span)
342 {
343 return (k64f)span / (60.0 * 60.0 * 1000000.0);
344 }
345
353 kInlineFx(k64s) kTimeSpan_ToMinutes64s(kTimeSpan span)
354 {
355 return span / (60LL * 1000000LL);
356 }
357
365 kInlineFx(k64f) kTimeSpan_ToMinutes64f(kTimeSpan span)
366 {
367 return (k64f)span / (60.0 * 1000000.0);
368 }
369
377 kInlineFx(k64s) kTimeSpan_ToSeconds64s(kTimeSpan span)
378 {
379 return span / 1000000LL;
380 }
381
389 kInlineFx(k64f) kTimeSpan_ToSeconds64f(kTimeSpan span)
390 {
391 return (k64f)span / 1000000.0;
392 }
393
401 kInlineFx(k64s) kTimeSpan_ToMilliseconds64s(kTimeSpan span)
402 {
403 return span / 1000LL;
404 }
405
413 kInlineFx(k64f) kTimeSpan_ToMilliseconds64f(kTimeSpan span)
414 {
415 return (k64f)span / 1000.0;
416 }
417
425 kInlineFx(k64s) kTimeSpan_ToMicroseconds64s(kTimeSpan span)
426 {
427 return span;
428 }
429
437 kInlineFx(k64f) kTimeSpan_ToMicroseconds64f(kTimeSpan span)
438 {
439 return (k64f)span;
440 }
441
452 kFx(kStatus) kTimeSpan_Format(kTimeSpan span, kTimeSpanFormat format, kChar* text, kSize capacity);
453
465 kFx(kStatus) kTimeSpan_Parse(kTimeSpan* span, kTimeSpanFormat format, const kChar* text);
466
467 #endif
kTimeSpan::kTimeSpan_ToDays64f
k64f kTimeSpan_ToDays64f(kTimeSpan span)
Reports the total days represented by the timespan.
Definition: kTimeSpan.h:317
kTimeSpan::kTimeSpan_FromHours64f
kTimeSpan kTimeSpan_FromHours64f(k64f hours)
Creates a timespan from a total number of hours.
Definition: kTimeSpan.h:197
kTimeSpan::kTimeSpan_ToSeconds64s
k64s kTimeSpan_ToSeconds64s(kTimeSpan span)
Reports the total seconds represented by the timespan.
Definition: kTimeSpan.h:377
kTimeSpan::kTimeSpan_HoursPart
k32s kTimeSpan_HoursPart(kTimeSpan span)
Gets broken-down hours component of the timespan.
Definition: kTimeSpan.h:113
kTimeSpan::kTimeSpan_FromSeconds64f
kTimeSpan kTimeSpan_FromSeconds64f(k64f seconds)
Creates a timespan from a total number of seconds.
Definition: kTimeSpan.h:245
kTimeSpan::kTimeSpan_FromMicroseconds64f
kTimeSpan kTimeSpan_FromMicroseconds64f(k64f microseconds)
Creates a timespan from a total number of microseconds.
Definition: kTimeSpan.h:293
kTimeSpanFormat
Represents a timespan text format.
kSize
Represents an unsigned integer that can store a pointer address.
kTimeSpan::kTimeSpan_ToHours64f
k64f kTimeSpan_ToHours64f(kTimeSpan span)
Reports the total hours represented by the timespan.
Definition: kTimeSpan.h:341
kTimeSpan::kTimeSpan_FromMilliseconds64f
kTimeSpan kTimeSpan_FromMilliseconds64f(k64f milliseconds)
Creates a timespan from a total number of milliseconds.
Definition: kTimeSpan.h:269
kTimeSpan::kTimeSpan_ToDays64s
k64s kTimeSpan_ToDays64s(kTimeSpan span)
Reports the total days represented by the timespan.
Definition: kTimeSpan.h:305
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kChar
Represents a single unit (byte) in a UTF-8 character.
kTimeSpan::kTimeSpan_FromParts
kTimeSpan kTimeSpan_FromParts(k32s daysPart, k32s hoursPart, k32s minutesPart, k32s secondsPart, k32s microsecondsPart)
Creates a timespan from broken-down time components.
Definition: kTimeSpan.h:75
kTimeSpan::kTimeSpan_ToMicroseconds64f
k64f kTimeSpan_ToMicroseconds64f(kTimeSpan span)
Reports the total microseconds represented by the timespan.
Definition: kTimeSpan.h:437
kTimeSpan::kTimeSpan_FromMicroseconds64s
kTimeSpan kTimeSpan_FromMicroseconds64s(k64s microseconds)
Creates a timespan from a total number of microseconds.
Definition: kTimeSpan.h:281
kTimeSpan::kTimeSpan_ToMilliseconds64f
k64f kTimeSpan_ToMilliseconds64f(kTimeSpan span)
Reports the total milliseconds represented by the timespan.
Definition: kTimeSpan.h:413
kMath.h
Math-related utilities.
kTimeSpan::kTimeSpan_ToHours64s
k64s kTimeSpan_ToHours64s(kTimeSpan span)
Reports the total hours represented by the timespan.
Definition: kTimeSpan.h:329
kTimeSpan::kTimeSpan_FromMilliseconds64s
kTimeSpan kTimeSpan_FromMilliseconds64s(k64s milliseconds)
Creates a timespan from a total number of milliseconds.
Definition: kTimeSpan.h:257
kTimeSpan::kTimeSpan_FromSeconds64s
kTimeSpan kTimeSpan_FromSeconds64s(k64s seconds)
Creates a timespan from a total number of seconds.
Definition: kTimeSpan.h:233
kTimeSpan::kTimeSpan_MinutesPart
k32s kTimeSpan_MinutesPart(kTimeSpan span)
Gets broken-down minutes component of the timespan.
Definition: kTimeSpan.h:125
kTimeSpan::kTimeSpan_ToMilliseconds64s
k64s kTimeSpan_ToMilliseconds64s(kTimeSpan span)
Reports the total milliseconds represented by the timespan.
Definition: kTimeSpan.h:401
kTimeSpan::kTimeSpan_FromMinutes64f
kTimeSpan kTimeSpan_FromMinutes64f(k64f minutes)
Creates a timespan from a total number of minutes.
Definition: kTimeSpan.h:221
kMath::kMath_Round64s_
#define kMath_Round64s_(A)
Rounds a floating-point value and casts to an 64-bit signed integer.
Definition: kMath.h:45
kTimeSpan::kTimeSpan_ToSeconds64f
k64f kTimeSpan_ToSeconds64f(kTimeSpan span)
Reports the total seconds represented by the timespan.
Definition: kTimeSpan.h:389
kTimeSpan::kTimeSpan_ToMinutes64f
k64f kTimeSpan_ToMinutes64f(kTimeSpan span)
Reports the total minutes represented by the timespan.
Definition: kTimeSpan.h:365
kApiDef.h
Core Zen type declarations.
k32s
Represents a 32-bit signed integer.
kTimeSpan::kTimeSpan_ToMicroseconds64s
k64s kTimeSpan_ToMicroseconds64s(kTimeSpan span)
Reports the total microseconds represented by the timespan.
Definition: kTimeSpan.h:425
kTimeSpan::kTimeSpan_Parts
kStatus kTimeSpan_Parts(kTimeSpan span, k32s *daysPart, k32s *hoursPart, k32s *minutesPart, k32s *secondsPart, k32s *microsecondsPart)
Gets broken-down time components from a timespan.
kTimeSpan::kTimeSpan_FromHours64s
kTimeSpan kTimeSpan_FromHours64s(k64s hours)
Creates a timespan from a total number of hours.
Definition: kTimeSpan.h:185
k64s
Represents a 64-bit signed integer.
kTimeSpan::kTimeSpan_Parse
kStatus kTimeSpan_Parse(kTimeSpan *span, kTimeSpanFormat format, const kChar *text)
Parses a time string that was formatted with kTimeSpan_Format.
kTimeSpan::kTimeSpan_DaysPart
k32s kTimeSpan_DaysPart(kTimeSpan span)
Gets broken-down days component of the timespan.
Definition: kTimeSpan.h:101
kTimeSpan::kTimeSpan_FromDays64f
kTimeSpan kTimeSpan_FromDays64f(k64f days)
Creates a timespan from a total number of days.
Definition: kTimeSpan.h:173
kTimeSpan::kTimeSpan_FromMinutes64s
kTimeSpan kTimeSpan_FromMinutes64s(k64s minutes)
Creates a timespan from a total number of minutes.
Definition: kTimeSpan.h:209
kTimeSpan::kTimeSpan_SecondsPart
k32s kTimeSpan_SecondsPart(kTimeSpan span)
Gets broken-down seconds component of the timespan.
Definition: kTimeSpan.h:137
kStatus
Represents an error code.
k64f
Represents a 64-bit floating-point number.
kTimeSpan::kTimeSpan_Format
kStatus kTimeSpan_Format(kTimeSpan span, kTimeSpanFormat format, kChar *text, kSize capacity)
Formats a time span value as a string.
kTimeSpan
Represents a span of time.
kTimeSpan::kTimeSpan_MicrosecondsPart
k32s kTimeSpan_MicrosecondsPart(kTimeSpan span)
Gets broken-down microseconds component of timespan.
Definition: kTimeSpan.h:149
kTimeSpan::kTimeSpan_ToMinutes64s
k64s kTimeSpan_ToMinutes64s(kTimeSpan span)
Reports the total minutes represented by the timespan.
Definition: kTimeSpan.h:353
kTimeSpan::kTimeSpan_FromDays64s
kTimeSpan kTimeSpan_FromDays64s(k64s days)
Creates a timespan from a total number of days.
Definition: kTimeSpan.h:161