cTzOffset

Overview

bla bla bla

Types and Definitions

cTzOffset

struct cTzOffset
{
   int32_t _v;
};
typedef struct cTzOffset cTzOffset;

A cTzOffset value represents the offset of a time zone.

Generated

cTzOffsetSlice

struct cTzOffsetSlice
{
int64_t s;
cTzOffset const* v;
};
typedef struct cTzOffsetSlice cTzOffsetSlice;

Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

/* init */
cTzOffsetSlice tz_offset_slice_c( int64_t s, cTzOffset const* v );
cTzOffsetSlice make_tz_offset_slice_c( cTzOffset const* beg,
                                       cTzOffset const* end );
cTzOffsetSlice empty_tz_offset_slice_c( void );
/* sub */
cTzOffsetSlice left_tz_offset_slice_c( cTzOffsetSlice slice, int64_t maxLen );
cTzOffsetSlice mid_tz_offset_slice_c( cTzOffsetSlice slice, int64_t index );
cTzOffsetSlice right_tz_offset_slice_c( cTzOffsetSlice slice, int64_t maxLen );
cTzOffsetSlice sub_tz_offset_slice_c( cTzOffsetSlice slice,
                                      int64_t begIdx,
                                      int64_t endIdx);

cVarTzOffsetSlice

struct cVarTzOffsetSlice
{
int64_t s;
cTzOffset* v;
};
typedef struct cVarTzOffsetSlice cVarTzOffsetSlice;

Via the macros SLICE_DEF_C_ and SLICE_IMPL_C_ declared and implemented struct. The macros declare and implement also the following functions.

/* init */
cVarTzOffsetSlice var_tz_offset_slice_c( int64_t s, cTzOffset* v );
cVarTzOffsetSlice make_var_tz_offset_slice_c( cTzOffset* beg,
                                              cTzOffset* end );
cVarTzOffsetSlice empty_var_tz_offset_slice_c( void );
/* sub */
cVarTzOffsetSlice left_var_tz_offset_slice_c( cVarTzOffsetSlice slice,
                                              int64_t maxLen );
cVarTzOffsetSlice mid_var_tz_offset_slice_c( cVarTzOffsetSlice slice,
                                             int64_t index );
cVarTzOffsetSlice right_var_tz_offset_slice_c( cVarTzOffsetSlice slice,
                                               int64_t maxLen );
cVarTzOffsetSlice sub_var_tz_offset_slice_c( cVarTzOffsetSlice slice,
                                             int64_t begIdx,
                                             int64_t endIdx);
/* var slice */
cVarTzOffsetSlice as_var_tz_offset_slice_c( cVarTzOffsetSlice slice );
cVarTzOffsetSlice cast_var_tz_offset_slice_c( cVarTzOffsetSlice slice,
                                              cTzOffsetSlice sub );
int64_t set_tz_offset_slice_c( cVarTzOffsetSlice dst, cTzOffsetSlice src );

Functions

init

local_c

cTzOffset local_c( void );

Returns the offset of the current local time zone.

null_tz_offset_c

cTzOffset null_tz_offset_c( void );

Returns an invalid time zone offset.

tz_c

cTzOffset tz_c( int64_t v );

Initalise a cTzOffset value from one int value that contains the hour and minute value.

utc_c

cTzOffset utc_c( void );

Returns the offset of the UTC time zone.

from

duration_from_tz_offset_c

cDuration duration_from_tz_offset_c( cTzOffset tz );

Creates a cDuration value from a cTzOffset value.

hmsn_from_tz_offset_c

cHmsn hmsn_from_tz_offset_c( cTzOffset tz );

Creates a cHmsn value from a cTzOffset value.

tz_offset_from_duration_c

cTzOffset tz_offset_from_duration_c( cDuration dur );

Creates a cTzOffset value from a cDuration value.

tz_offset_from_hmsn_c

cTzOffset tz_offset_from_hmsn_c( cHmsn hmsn );

Creates a cTzOffset value from a cHmsn value.

cmp

cmp_tz_offset_c

int cmp_tz_offset_c( cTzOffset a, cTzOffset b );

Compares two time zone offsets and returns the three possible results:

<0

if the a offset is lower as b

0

if both offsets are equal

>0

if the a offset is higher as b

eq_tz_offset_c

bool eq_tz_offset_c( cTzOffset a, cTzOffset b );

Returns true if a is equal to b, otherwise false.

diff

between_tz_offsets_c

cDuration between_tz_offsets_c( cTzOffset a, cTzOffset b );

Returns the duration between time zone values.

Example
#include "clingo/lang/expect.h"
#include "clingo/time/cTzOffset.h"

TEMP_SLICE_DEF_C_(
   test,
   {
      cTzOffset a;
      cTzOffset b;
      cDuration exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   cTzOffset utc  = utc_c();
   cTzOffset almt = tz_c( +600 );
   cTzOffset pst  = tz_c( -800 );

   testSlice tests = slice_c_( test,
      t_( utc, almt, hours_c( 6 ) ),
      t_( almt, utc, hours_c( -6 ) ),
      t_( utc, pst, hours_c( -8 ) ),
      t_( pst, utc, hours_c( 8 ) ),
      t_( pst, almt, hours_c( 14 ) ),
      t_( almt, pst, hours_c( -14 ) )
   );

   for_each_c_( test const*, t, tests )
   {
      cDuration dur = between_tz_offsets_c( t->a, t->b );

      bool res = eq_c( cmp_duration_c( dur, t->exp ) );

      cRecorder* rec = &recorder_c_( 256 );
      write_duration_c_( rec, dur );
      tap_descf_c( res, "test: %s", turn_into_cstr_c( rec ) );
   }

   return finish_tap_c_();
}

io

The functions read_tz_offset_c and write_tz_offset_c are using the following format:

Table 1. format

o

The offset in the +hh:mm format, where the mm part is optional

+00, +10 or -04:30

oo

The offset in the +hh:mm format

+00:00, +10 or -04:30

oooo

The offset in the +hhmm format

+0000, +1000 or -0430

z

Like "o", but the UTC offset will be replaced with a Z

Z, +10 or -04:30

zz

Like "oo", but the UTC offset will be replaced with a Z

Z, +10:00 or -04:30

zzzz

Like "oooo", but the UTC offset will be replaced with a Z

Z, +1000 or -0430

read_tz_offset_c

#define read_tz_offset_c_( Sca, Tz )                                           \
   read_tz_offset_c( (Sca), (Tz), "" )
bool read_tz_offset_c( cScanner sca[static 1],
                       cTzOffset tz[static 1],
                       char const fmt[static 1] );

Reads a cTzOffset value from a text with a scanner. The function will use "oo" as default format.

Example
#include "clingo/lang/expect.h"
#include "clingo/time/cTzOffset.h"

TEMP_SLICE_DEF_C_(
   test,
   {
      char const* str;
      char const* fmt;
      cTzOffset exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( "+04:30", "o", tz_c( +430 ) ),
      t_( "+04:30", "oo", tz_c( +430 ) ),
      t_( "+0430", "oooo", tz_c( +430 ) ),
      t_( "-07", "z", tz_c( -700 ) ),
      t_( "-07:00", "zz", tz_c( -700 ) ),
      t_( "-0700", "zzzz", tz_c( -700 ) ),
      t_( "+00", "o", tz_c( 0 ) ),
      t_( "Z", "z", tz_c( 0 ) )
   );

   for_each_c_( test const*, t, tests )
   {
      cScanner* sca = &cstr_scanner_c_( t->str );

      cTzOffset tz;
      bool res = read_tz_offset_c( sca, &tz, t->fmt );
      res &= eq_c( cmp_tz_offset_c( tz, t->exp ) );

      tap_descf_c( res, "test: %s with %s", t->str, t->fmt );
   }

   return finish_tap_c_();
}

write_tz_offset_c

#define write_tz_offset_c_( Rec, Tz )                                          \
   write_tz_offset_c( (Rec), (Tz), "" )
bool write_tz_offset_c( cRecorder rec[static 1],
                        cTzOffset tz,
                        char const fmt[static 1] );

Writes a cTzOffset value into the recorder. The function will use "oo" as default format.

Example
#include "clingo/lang/expect.h"
#include "clingo/time/cTzOffset.h"

TEMP_SLICE_DEF_C_(
   test,
   {
      cTzOffset tz;
      char const* fmt;
      char const* exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( tz_c( +430 ), "o", "+04:30" ),
      t_( tz_c( +430 ), "oo", "+04:30" ),
      t_( tz_c( +430 ), "oooo", "+0430" ),
      t_( tz_c( -700 ), "z", "-07" ),
      t_( tz_c( -700 ), "zz", "-07:00" ),
      t_( tz_c( -700 ), "zzzz", "-0700" ),
      t_( tz_c( 0 ), "o", "+00" ),
      t_( tz_c( 0 ), "z", "Z" )
   );

   for_each_c_( test const*, t, tests )
   {
      cRecorder* rec = &recorder_c_( 32 );

      bool res = write_tz_offset_c( rec, t->tz, t->fmt );
      res &= recorded_is_c( rec, t->exp );

      tap_descf_c( res, "'%s' -> '%s'", t->fmt, turn_into_cstr_c( rec ) );
   }

   return finish_tap_c_();
}