Hash :
4ddf919a
Author :
Thomas de Grivel
Date :
2023-12-12T03:46:19
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
/* c3
* Copyright 2022,2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <assert.h>
#include "tag.h"
#include "time.h"
s_time * time_sub (const s_time *a, const s_time *b, s_time *dest)
{
if ((a->tv_nsec - b->tv_nsec) < 0) {
dest->tv_sec = a->tv_sec - b->tv_sec - 1;
dest->tv_nsec = 1000000000 + a->tv_nsec - b->tv_nsec;
} else {
dest->tv_sec = a->tv_sec - b->tv_sec;
dest->tv_nsec = a->tv_nsec - b->tv_nsec;
}
return dest;
}
f64 * time_to_f64 (const s_time *time, f64 *dest)
{
*dest = (f64) time->tv_sec + (f64) time->tv_nsec * 0.000000001;
return dest;
}
s_tag * time_to_tag (const s_time *time, s_tag *dest)
{
s_tag tmp;
assert(time);
if (! tag_init_tuple(&tmp, 2))
return NULL;
tag_init_s64(&tmp.data.tuple.tag[0], time->tv_sec);
tag_init_s64(&tmp.data.tuple.tag[1], time->tv_nsec);
*dest = tmp;
return dest;
}