c_WeekDay

Overview

Types and Definitions

definitions

cWEEKDAY_

#define cWEEKDAY_

Defines the c_Weekday values.

c_Weekday

enum c_Month {
   c_Mon = 1,
   c_Tue = 2,
   c_Wed = 3,
   c_Thu = 4,
   c_Fri = 5,
   c_Sat = 6,
   c_Sun = 7,
};
type enum c_Weekday c_Weekday;

Enum type to represent a weekday.

Functions

overall

int64_to_weekday_c

bool int64_to_weekday_c( int64_t src, c_Weekday dst[static 1] );

Returns true if the int64_t value can be represented in a c_Weekday variable, otherwise false.

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

int main( void )
{
   init_tap_c_();

   c_Weekday wd;

   expect_c_( int64_to_weekday_c( 1, &wd ) );
   expect_c_( wd == c_Mon );

   expect_c_( int64_to_weekday_c( 4, &wd ) );
   expect_c_( wd == c_Thu );

   expect_c_( int64_to_weekday_c( 7, &wd ) );
   expect_c_( wd == c_Sun );

   expect_c_( !int64_to_weekday_c( 8, &wd ) );

   return finish_tap_c_();
}

stringify_weekday_c

char const* stringify_weekday_c( c_Weekday wd );

Returns the string representation of a value.

Example
#include "clingo/lang/expect.h"
#include "clingo/time/c_Weekday.h"
#include "clingo/type/cChars.h"

TEMP_SLICE_C_(
   test,
   {
      c_Weekday wd;
      char const* exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( c_Mon, "c_Mon" ),
      t_( c_Tue, "c_Tue" ),
      t_( c_Wed, "c_Wed" ),
      t_( c_Thu, "c_Thu" ),
      t_( c_Fri, "c_Fri" ),
      t_( c_Sat, "c_Sat" ),
      t_( c_Sun, "c_Sun" )
   );

   for_each_c_( test const*, t, tests )
   {
      cChars chars = c_c( stringify_weekday_c( t->wd ) );
      bool res = chars_is_c( chars, t->exp );

      tap_descf_c( res, "test %s", t->exp );
   }

   return finish_tap_c_();
}

tm_wday_to_weekday_c

bool tm_wday_to_weekday_c( int src, c_Weekday dst[static 1] );

Returns true if the tm_wday can be converted to a weekday, otherwise false.

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

int main( void )
{
   init_tap_c_();

   c_Weekday wd;

   expect_c_( tm_wday_to_weekday_c( 0, &wd ) );
   expect_c_( wd == c_Sun );

   expect_c_( tm_wday_to_weekday_c( 4, &wd ) );
   expect_c_( wd == c_Thu );

   expect_c_( tm_wday_to_weekday_c( 6, &wd ) );
   expect_c_( wd == c_Sat );

   expect_c_( !tm_wday_to_weekday_c( 7, &wd ) );

   return finish_tap_c_();
}

weekday_c

c_Weekday weekday_c( int32_t year, c_Month month, int8_t day );

Determines the weekday of a date.

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

TEMP_SLICE_C_(
   test,
   {
      int32_t year;
      c_Month month;
      int8_t day;
      c_Weekday exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( 1789, c_Jul, 14, c_Tue ),
      t_( 1892, c_Jan, 18, c_Mon ),
      t_( 1949, c_May, 23, c_Mon ),
      t_( 1989, c_Nov,  9, c_Thu ),
      t_( 2012, c_Apr,  8, c_Sun )
   );

   for_each_c_( test const*, t, tests )
   {
      bool res = weekday_c( t->year, t->month, t->day ) == t->exp;

      tap_descf_c( res, "test: %d.%d.%d -> %s",
                   t->year, t->month, t->day, stringify_weekday_c( t->exp ) );
   }

   return finish_tap_c_();
}

itr

next_weekday_c

c_Weekday next_weekday_c( c_Weekday wd );

Returns the weekday after wd.

prev_weekday_c

c_Weekday prev_weekday_c( c_Weekday wd );

Returns the weekday before wd.

text

get_weekday_abbrev_c

cVarChars get_weekday_abbrev_c( c_Weekday wd, cVarChars chars );

Writes the local abbreviation for the weekday into the chars buffer.

Example
#include "clingo/lang/expect.h"
#include "clingo/lang/locale.h"
#include "clingo/time/c_Weekday.h"
#include "clingo/type/cChars.h"

TEMP_SLICE_C_(
   test,
   {
      c_Weekday wd;
      char const* exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   set_locale_c( LC_TIME, "C" ); // For every system the same output

   testSlice tests = slice_c_( test,
      t_( c_Mon, "Mon" ),
      t_( c_Tue, "Tue" ),
      t_( c_Wed, "Wed" ),
      t_( c_Thu, "Thu" ),
      t_( c_Fri, "Fri" ),
      t_( c_Sat, "Sat" ),
      t_( c_Sun, "Sun" )
   );

   for_each_c_( test const*, t, tests )
   {
      cVarChars varChars = scalars_c_( 16, char );
      varChars = get_weekday_abbrev_c( t->wd, varChars );
      cChars chars = as_c_( cChars, varChars );
      bool res = chars_is_c( chars, t->exp );

      tap_descf_c( res, "test %s", t->exp );
   }

   return finish_tap_c_();
}

get_weekday_name_c

cVarChars get_weekday_name_c( c_Weekday wd, cVarChars chars );

Writes the local name for the weekday into the chars buffer.

Example
#include "clingo/lang/expect.h"
#include "clingo/lang/locale.h"
#include "clingo/time/c_Weekday.h"
#include "clingo/type/cChars.h"

TEMP_SLICE_C_(
   test,
   {
      c_Weekday wd;
      char const* exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   set_locale_c( LC_TIME, "C" ); // For every system the same output

   testSlice tests = slice_c_( test,
      t_( c_Mon, "Monday" ),
      t_( c_Tue, "Tuesday" ),
      t_( c_Wed, "Wednesday" ),
      t_( c_Thu, "Thursday" ),
      t_( c_Fri, "Friday" ),
      t_( c_Sat, "Saturday" ),
      t_( c_Sun, "Sunday" )
   );

   for_each_c_( test const*, t, tests )
   {
      cVarChars varChars = scalars_c_( 16, char );
      varChars = get_weekday_name_c( t->wd, varChars );
      cChars chars = as_c_( cChars, varChars );
      bool res = chars_is_c( chars, t->exp );

      tap_descf_c( res, "test %s", t->exp );
   }

   return finish_tap_c_();
}

io

The read and write function are using the following format:

Table 1. format

E

The weekday as a number

1 to 7

EEE

The abbreviated localized weekday name

Mon to Sun

EEEE

The localized weekday name

Monday to Sunday

read_weekday_c

#define read_weekday_c_( Sca, Wd )                                             \
   read_weekday_c( (Sca), (Wd), "" )
bool read_weekday_c( cScanner sca[static 1],
                     c_Weekday wd[static 1],
                     char const* fmt );

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

write_weekday_c

#define write_weekday_c_( Rec, Wd )                                            \
   write_weekday_c( (Rec), (Wd), "" )
bool write_weekday_c( cRecorder rec[static 1],
                      c_Weekday wd,
                      char const* fmt );

Writes a c_Weekday value into the recorder. The function will use "EEE" as default format.