Zen API
 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 
102 {
103  return (k32s) (span / (24LL * 60LL * 60LL * 1000000LL));
104 }
105 
114 {
115  return (k32s) ((span / (60LL * 60LL * 1000000LL)) % 24LL);
116 }
117 
126 {
127  return (k32s) ((span / (60LL * 1000000LL)) % 60LL);
128 }
129 
138 {
139  return (k32s) ((span / 1000000LL) % 60LL);
140 }
141 
150 {
151  return (k32s) (span % 1000000LL);
152 }
153 
162 {
163  return days * 24LL * 60LL * 60LL * 1000000LL;
164 }
165 
174 {
175  return (kTimeSpan) kMath_Round64s_(days * 24.0 * 60.0 * 60.0 * 1000000.0);
176 }
177 
186 {
187  return hours * 60LL * 60LL * 1000000LL;
188 }
189 
198 {
199  return (kTimeSpan) kMath_Round64s_(hours * 60.0 * 60.0 * 1000000.0);
200 }
201 
210 {
211  return minutes * 60LL * 1000000LL;
212 }
213 
222 {
223  return (kTimeSpan) kMath_Round64s_(minutes * 60.0 * 1000000.0);
224 }
225 
234 {
235  return seconds * 1000000LL;
236 }
237 
246 {
247  return (kTimeSpan) kMath_Round64s_(seconds * 1000000.0);
248 }
249 
258 {
259  return milliseconds * 1000LL;
260 }
261 
270 {
271  return (kTimeSpan) kMath_Round64s_(milliseconds * 1000LL);
272 }
273 
282 {
283  return microseconds;
284 }
285 
294 {
295  return (kTimeSpan) kMath_Round64s_(microseconds);
296 }
297 
306 {
307  return span / (24LL * 60LL * 60LL * 1000000LL);
308 }
309 
318 {
319  return (k64f)span / (24.0 * 60.0 * 60.0 * 1000000.0);
320 }
321 
330 {
331  return span / (60LL * 60LL * 1000000LL);
332 }
333 
342 {
343  return (k64f)span / (60.0 * 60.0 * 1000000.0);
344 }
345 
354 {
355  return span / (60LL * 1000000LL);
356 }
357 
366 {
367  return (k64f)span / (60.0 * 1000000.0);
368 }
369 
378 {
379  return span / 1000000LL;
380 }
381 
390 {
391  return (k64f)span / 1000000.0;
392 }
393 
402 {
403  return span / 1000LL;
404 }
405 
414 {
415  return (k64f)span / 1000.0;
416 }
417 
426 {
427  return span;
428 }
429 
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
k64f kTimeSpan_ToDays64f(kTimeSpan span)
Reports the total days represented by the timespan.
Definition: kTimeSpan.h:317
kTimeSpan kTimeSpan_FromHours64f(k64f hours)
Creates a timespan from a total number of hours.
Definition: kTimeSpan.h:197
k64s kTimeSpan_ToSeconds64s(kTimeSpan span)
Reports the total seconds represented by the timespan.
Definition: kTimeSpan.h:377
k32s kTimeSpan_HoursPart(kTimeSpan span)
Gets broken-down hours component of the timespan.
Definition: kTimeSpan.h:113
kTimeSpan kTimeSpan_FromSeconds64f(k64f seconds)
Creates a timespan from a total number of seconds.
Definition: kTimeSpan.h:245
kTimeSpan kTimeSpan_FromMicroseconds64f(k64f microseconds)
Creates a timespan from a total number of microseconds.
Definition: kTimeSpan.h:293
Represents a timespan text format.
Represents an unsigned integer that can store a pointer address.
k64f kTimeSpan_ToHours64f(kTimeSpan span)
Reports the total hours represented by the timespan.
Definition: kTimeSpan.h:341
kTimeSpan kTimeSpan_FromMilliseconds64f(k64f milliseconds)
Creates a timespan from a total number of milliseconds.
Definition: kTimeSpan.h:269
k64s kTimeSpan_ToDays64s(kTimeSpan span)
Reports the total days represented by the timespan.
Definition: kTimeSpan.h:305
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
Represents a single unit (byte) in a UTF-8 character.
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
k64f kTimeSpan_ToMicroseconds64f(kTimeSpan span)
Reports the total microseconds represented by the timespan.
Definition: kTimeSpan.h:437
kTimeSpan kTimeSpan_FromMicroseconds64s(k64s microseconds)
Creates a timespan from a total number of microseconds.
Definition: kTimeSpan.h:281
k64f kTimeSpan_ToMilliseconds64f(kTimeSpan span)
Reports the total milliseconds represented by the timespan.
Definition: kTimeSpan.h:413
Math-related utilities.
k64s kTimeSpan_ToHours64s(kTimeSpan span)
Reports the total hours represented by the timespan.
Definition: kTimeSpan.h:329
kTimeSpan kTimeSpan_FromMilliseconds64s(k64s milliseconds)
Creates a timespan from a total number of milliseconds.
Definition: kTimeSpan.h:257
kTimeSpan kTimeSpan_FromSeconds64s(k64s seconds)
Creates a timespan from a total number of seconds.
Definition: kTimeSpan.h:233
k32s kTimeSpan_MinutesPart(kTimeSpan span)
Gets broken-down minutes component of the timespan.
Definition: kTimeSpan.h:125
k64s kTimeSpan_ToMilliseconds64s(kTimeSpan span)
Reports the total milliseconds represented by the timespan.
Definition: kTimeSpan.h:401
kTimeSpan kTimeSpan_FromMinutes64f(k64f minutes)
Creates a timespan from a total number of minutes.
Definition: kTimeSpan.h:221
#define kMath_Round64s_(A)
Rounds a floating-point value and casts to an 64-bit signed integer.
Definition: kMath.h:45
k64f kTimeSpan_ToSeconds64f(kTimeSpan span)
Reports the total seconds represented by the timespan.
Definition: kTimeSpan.h:389
k64f kTimeSpan_ToMinutes64f(kTimeSpan span)
Reports the total minutes represented by the timespan.
Definition: kTimeSpan.h:365
Core Zen type declarations.
Represents a 32-bit signed integer.
k64s kTimeSpan_ToMicroseconds64s(kTimeSpan span)
Reports the total microseconds represented by the timespan.
Definition: kTimeSpan.h:425
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(k64s hours)
Creates a timespan from a total number of hours.
Definition: kTimeSpan.h:185
Represents a 64-bit signed integer.
kStatus kTimeSpan_Parse(kTimeSpan *span, kTimeSpanFormat format, const kChar *text)
Parses a time string that was formatted with kTimeSpan_Format.
k32s kTimeSpan_DaysPart(kTimeSpan span)
Gets broken-down days component of the timespan.
Definition: kTimeSpan.h:101
kTimeSpan kTimeSpan_FromDays64f(k64f days)
Creates a timespan from a total number of days.
Definition: kTimeSpan.h:173
kTimeSpan kTimeSpan_FromMinutes64s(k64s minutes)
Creates a timespan from a total number of minutes.
Definition: kTimeSpan.h:209
k32s kTimeSpan_SecondsPart(kTimeSpan span)
Gets broken-down seconds component of the timespan.
Definition: kTimeSpan.h:137
Represents an error code.
Represents a 64-bit floating-point number.
kStatus kTimeSpan_Format(kTimeSpan span, kTimeSpanFormat format, kChar *text, kSize capacity)
Formats a time span value as a string.
Represents a span of time.
k32s kTimeSpan_MicrosecondsPart(kTimeSpan span)
Gets broken-down microseconds component of timespan.
Definition: kTimeSpan.h:149
k64s kTimeSpan_ToMinutes64s(kTimeSpan span)
Reports the total minutes represented by the timespan.
Definition: kTimeSpan.h:353
kTimeSpan kTimeSpan_FromDays64s(k64s days)
Creates a timespan from a total number of days.
Definition: kTimeSpan.h:161