cDaytime
Overview
Types and Definitions
cDaytime
struct cDaytime
{
int64_t _v;
};
typedef struct cDaytime cDaytime;
The cDaytime struct has just the attribute _v that represent the watch time of a day.
Generated
cDaytimeSlice
struct cDaytimeSlice
{
int64_t s;
cDaytime const* v;
};
typedef struct cDaytimeSlice cDaytimeSlice;
Via the macro SLICES_C_ generated struct.
cVarDaytimeSlice
struct cVarDaytimeSlice
{
int64_t s;
cDaytime* v;
};
typedef struct cVarDaytimeSlice cVarDaytimeSlice;
Via the macro SLICES_C_ generated struct.
Functions
init
daytime_c
#define daytime_c_( H, M, S ) \
daytime_c( (H), (M), (S), 0 )
cDaytime daytime_c( int64_t h, int64_t m, int64_t s, int64_t n );
Initialise a daytime with hour, minute and second.
local_daytime_c
cDaytime local_daytime_c( void );
Returns the current local daytime, as reported by the system clock.
null_daytime_c
cDaytime null_daytime_c( void );
Returns a null daytime, null daytimes are invalid.
utc_daytime_c
cDaytime utc_daytime_c( void );
Returns the current UTC date, as reported by the system clock.
from
from_duration_c
cDaytime from_duration_c( cDuration dur );
Creates a daytime from the cDuration value.
from_hmsn_c
cDaytime from_hmsn_c( cHmsn hmsn );
Creates a daytime from the hour, min, sec and nsec value from the cHmsn value.
as
as_duration_c
cDuration as_duration_c( cDaytime dt );
Returns the daytime as cDuration value.
as_hmsn_c
cHmsn as_hmsn_c( cDaytime dt );
Returns the daytime as cHmsn value.
add
add_to_daytime_c
cDaytime add_to_daytime_c( cDaytime dt, cDuration dur );
Adds a duration to the daytime.
#include "clingo/lang/expect.h"
#include "clingo/time/cDaytime.h"
TEMP_SLICE_C_(
test,
{
cDaytime base;
cDuration dur;
cDaytime exp;
}
)
#define t_( ... ) ((test){__VA_ARGS__})
int main( void )
{
init_tap_c_();
testSlice tests = slice_c_( test,
t_( daytime_c_( 20, 58, 0 ), hours_c( 7 ), daytime_c_( 3, 58, 0 ) ),
t_( daytime_c_( 3, 58, 0 ), mins_c( -49 ), daytime_c_( 3, 9, 0 ) ),
t_( daytime_c_( 15, 58, 0 ), mins_c( 2 ), daytime_c_( 16, 0, 0 ) ),
t_( daytime_c_( 16, 0, 0 ), mins_c( -100 ), daytime_c_( 14, 20, 0 ) ),
t_( daytime_c_( 10, 39, 44 ), secs_c( 23 ), daytime_c_( 10, 40, 7 ) )
);
for_each_c_( test const*, t, tests )
{
cDaytime dt = add_to_daytime_c( t->base, t->dur );
bool res = eq_daytime_c( dt, t->exp );
cHmsn t = as_hmsn_c( dt );
tap_descf_c( res, "%d:%d:%d", t.hour, t.min, t.sec );
}
return finish_tap_c_();
}
diff
between_daytimes_c
cDuration between_daytimes_c( cDaytime a, cDaytime b );
Returns the duration between two duration values.
#include "clingo/lang/expect.h"
#include "clingo/time/cDaytime.h"
int main( void )
{
init_tap_c_();
cDaytime a = daytime_c_( 21, 20, 37 );
cDaytime b = daytime_c_( 13, 37, 58 );
cDuration dur = duration_c( 7, 42, 39, 0 );
cDuration rud = invert_duration_c( dur );
expect_c_( eq_duration_c( between_daytimes_c( a, b ), rud ) );
expect_c_( eq_duration_c( between_daytimes_c( b, a ), dur ) );
return finish_tap_c_();
}
cmp
cmp_daytime_c
int cmp_daytime_c( cDaytime a, cDaytime b );
Compares two daytimes and returns the three possible results:
- <0
-
if a is earlier as b
- 0
-
if both dates are equal
- >0
-
if a is later as b
daytime_is_valid_c
bool daytime_is_valid_c( cDaytime dt );
Returns true if the daytime value is valid, otherwise false.
early_daytime_c
cDaytime early_daytime_c( cDaytime a, cDaytime b );
Returns the earlier of both daytimes. An invalid daytime is allways earlier as a valid daytime.
#include "clingo/lang/expect.h"
#include "clingo/time/cDaytime.h"
int main( void )
{
init_tap_c_();
cDaytime a = daytime_c_( 21, 20, 37 );
cDaytime b = daytime_c_( 13, 37, 58 );
cDaytime n = null_daytime_c();
expect_c_( eq_daytime_c( early_daytime_c( a, b ), b ) );
expect_c_( eq_daytime_c( early_daytime_c( n, b ), n ) );
return finish_tap_c_();
}
eq_daytime_c
bool eq_daytime_c( cDaytime a, cDaytime b );
Returns true if a is equal to b, otherwise returns false.
late_daytime_c
cDaytime late_daytime_c( cDaytime a, cDaytime b );
Returns the later of both daytimes. A valid daytime is allways later as an invalid daytime.
#include "clingo/lang/expect.h"
#include "clingo/time/cDaytime.h"
int main( void )
{
init_tap_c_();
cDaytime a = daytime_c_( 21, 20, 37 );
cDaytime b = daytime_c_( 13, 37, 58 );
cDaytime n = null_daytime_c();
expect_c_( eq_daytime_c( late_daytime_c( a, b ), a ) );
expect_c_( eq_daytime_c( late_daytime_c( n, b ), b ) );
return finish_tap_c_();
}
io
The functions read_daytime_c and write_daytime_c are using the following format:
h |
The hour without a leading character |
0 to 23 |
_h |
The hour with a leading space |
0 to 23 |
hh |
The hour with a leading zero |
00 to 23 |
k |
The kitchen hour without a leading character |
|
_k |
The kitchen hour with a leading space |
|
kk |
The kitchen hour with a leading zero |
|
m |
The minute without a leading character |
0 to 59 |
_m |
The minute with a leading space |
0 to 59 |
mm |
The minute with a leading zero |
00 to 59 |
s |
The whole second, without a leading character |
0 to 59 |
_s |
The whole second, with a leading space |
0 to 59 |
ss |
The whole second, with a leading zero |
00 to 59 |
i |
The fractional part of the second in millisecond whithout trainling zeros |
000 to 999 |
iii |
The fractional part of the second in millisecond with trailing zeros |
000 to 999 |
u |
The fractional part of the second in microsecond without trailing zeros |
000000 to 999999 |
uuu |
The fractional part of the second in microsecond with trailing zeros |
000000 to 999999 |
n |
The fractional part of the second in nanosecond without trailing zeros |
000000000 to 999999999 |
nnn |
The fractional part of the second in nanosecond with trailing zeros |
000000000 to 999999999 |
ap |
Read or write AM or PM dependent on the hour value |
|
AP |
Read or write am or pm dependent on the hour value |
read_daytime_c
bool read_daytime_c( cScanner sca[static 1],
cDaytime dt[static 1],
char const fmt[static 1] );
Reads a cDaytime value from a text with a scanner. The function will use C_DaytimeFormat( "hh:mm:ss.n" ) as default format.
write_daytime_c
bool write_daytime_c( cRecorder rec[static 1],
cDaytime dt,
char const fmt[static 1] );
Writes a cDaytime value into the recorder. The function will use C_DaytimeFormat( "hh:mm:ss.n" ) as default format.