c_Month

Overview

Types and Definitions

definitions

cMONTH_

#define cMONTH_

Defines the c_Month values.

c_Month

enum c_Month {
   c_Jan =  1,
   c_Feb =  2,
   c_Mar =  3,
   c_Apr =  4,
   c_May =  5,
   c_Jun =  6,
   c_Jul =  7,
   c_Aug =  8,
   c_Sep =  9,
   c_Oct = 10,
   c_Nov = 11,
   c_Dec = 12,
};
type enum c_Month c_Month;

Enum type to represent a month.

Functions

overall

int64_to_month_c

bool int64_to_month_c( int64_t src, c_Month dst[static 1] );

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

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

int main( void )
{
   init_tap_c_();

   c_Month month;

   expect_c_( int64_to_month_c( 1, &month ) );
   expect_c_( month == c_Jan );

   expect_c_( int64_to_month_c( 10, &month ) );
   expect_c_( month == c_Oct );

   expect_c_( int64_to_month_c( 12, &month ) );
   expect_c_( month == c_Dec );

   expect_c_( !int64_to_month_c( 1000, &month ) );

   return finish_tap_c_();
}

stringify_month_c

char const* stringify_month_c( c_Month month );

Returns the string representation of a value.

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

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

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( c_Jan, "c_Jan" ),
      t_( c_Feb, "c_Feb" ),
      t_( c_Mar, "c_Mar" ),
      t_( c_Apr, "c_Apr" ),
      t_( c_May, "c_May" ),
      t_( c_Jun, "c_Jun" ),
      t_( c_Jul, "c_Jul" ),
      t_( c_Aug, "c_Aug" ),
      t_( c_Sep, "c_Sep" ),
      t_( c_Oct, "c_Oct" ),
      t_( c_Nov, "c_Nov" ),
      t_( c_Dec, "c_Dec" )
   );

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

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

   return finish_tap_c_();
}

days

days_per_month_c

#define days_per_month_c_( Month, Year )                                       \
   days_per_month_c( Month, is_leap_year_c( Year ) )
int8_t days_per_month_c( c_Month month, bool leapYear );

Returns the number of days a month has.

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

TEMP_SLICE_C_(
   test,
   {
      c_Month month;
      int8_t expF;
      int8_t expT;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( c_Jan, 31, 31 ),
      t_( c_Feb, 28, 29 ),
      t_( c_Mar, 31, 31 ),
      t_( c_Apr, 30, 30 ),
      t_( c_May, 31, 31 ),
      t_( c_Jun, 30, 30 ),
      t_( c_Jul, 31, 31 ),
      t_( c_Aug, 31, 31 ),
      t_( c_Sep, 30, 30 ),
      t_( c_Oct, 31, 31 ),
      t_( c_Nov, 30, 30 ),
      t_( c_Dec, 31, 31 )
   );

   for_each_c_( test const*, t, tests )
   {
      char const* monthStr = stringify_month_c( t->month );
      int8_t days;

      days = days_per_month_c( t->month, false );
      tap_descf_c( days == t->expF, "%s no leap year: %d", monthStr, days );
      days = days_per_month_c( t->month, true );
      tap_descf_c( days == t->expT, "%s leap year: %d", monthStr, days );
   }

   return finish_tap_c_();
}

first_month_day_of_year_c

#define first_month_day_of_year_c_( Month, Year )                              \
   first_month_day_of_year_c( Month, is_leap_year_c( Year ) )
int16_t first_month_day_of_year_c( c_Month month, bool leapYear );

Returns the day in year of the first day in the month.

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

TEMP_SLICE_C_(
   test,
   {
      c_Month month;
      int16_t expF;
      int16_t expT;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( c_Jan,   1,   1 ),
      t_( c_Feb,  32,  32 ),
      t_( c_Mar,  60,  61 ),
      t_( c_Apr,  91,  92 ),
      t_( c_May, 121, 122 ),
      t_( c_Jun, 152, 153 ),
      t_( c_Jul, 182, 183 ),
      t_( c_Aug, 213, 214 ),
      t_( c_Sep, 244, 245 ),
      t_( c_Oct, 274, 275 ),
      t_( c_Nov, 305, 306 ),
      t_( c_Dec, 335, 336 )
   );

   for_each_c_( test const*, t, tests )
   {
      char const* monthStr = stringify_month_c( t->month );
      int16_t days;

      days = first_month_day_of_year_c( t->month, false );
      tap_descf_c( days == t->expF, "%s no leap year: %d", monthStr, days );
      days = first_month_day_of_year_c( t->month, true );
      tap_descf_c( days == t->expT, "%s leap year: %d", monthStr, days );
   }

   return finish_tap_c_();
}

first_month_of_quarter_c

c_Month first_month_of_quarter_c( c_Month month );

Returns the first month in the quarter of the month.

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

TEMP_SLICE_C_(
   test,
   {
      c_Month month;
      c_Month exp;
   }
)
#define t_( ... ) ((test){__VA_ARGS__})

int main( void )
{
   init_tap_c_();

   testSlice tests = slice_c_( test,
      t_( c_Jan, c_Jan ),
      t_( c_Feb, c_Jan ),
      t_( c_Mar, c_Jan ),
      t_( c_Apr, c_Apr ),
      t_( c_May, c_Apr ),
      t_( c_Jun, c_Apr ),
      t_( c_Jul, c_Jul ),
      t_( c_Aug, c_Jul ),
      t_( c_Sep, c_Jul ),
      t_( c_Oct, c_Oct ),
      t_( c_Nov, c_Oct ),
      t_( c_Dec, c_Oct )
   );

   for_each_c_( test const*, t, tests )
   {
      c_Month const res = first_month_of_quarter_c( t->month );

      tap_descf_c( res == t->exp, "%s -> %s", stringify_month_c( t->month ),
                                              stringify_month_c( res ) );
   }

   return finish_tap_c_();
}

itr

next_month_c

c_Month next_month_c( c_Month m );

Returns the month after m.

prev_month_c

c_Month prev_month_c( c_Month m );

Returns the month before m.

text

get_month_abbrev_c

cVarChars get_month_abbrev_c( c_Month month, cVarChars chars );

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

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

TEMP_SLICE_C_(
   test,
   {
      c_Month month;
      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_Jan, "Jan" ),
      t_( c_Feb, "Feb" ),
      t_( c_Mar, "Mar" ),
      t_( c_Apr, "Apr" ),
      t_( c_May, "May" ),
      t_( c_Jun, "Jun" ),
      t_( c_Jul, "Jul" ),
      t_( c_Aug, "Aug" ),
      t_( c_Sep, "Sep" ),
      t_( c_Oct, "Oct" ),
      t_( c_Nov, "Nov" ),
      t_( c_Dec, "Dec" )
   );

   for_each_c_( test const*, t, tests )
   {
      cVarChars varChars = scalars_c_( 16, char );
      varChars = get_month_abbrev_c( t->month, 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_month_name_c

cVarChars get_month_name_c( c_Month month, cVarChars chars );

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

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

TEMP_SLICE_C_(
   test,
   {
      c_Month month;
      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_Jan, "January" ),
      t_( c_Feb, "February" ),
      t_( c_Mar, "March" ),
      t_( c_Apr, "April" ),
      t_( c_May, "May" ),
      t_( c_Jun, "June" ),
      t_( c_Jul, "July" ),
      t_( c_Aug, "August" ),
      t_( c_Sep, "September" ),
      t_( c_Oct, "October" ),
      t_( c_Nov, "November" ),
      t_( c_Dec, "December" )
   );

   for_each_c_( test const*, t, tests )
   {
      cVarChars varChars = scalars_c_( 16, char );
      varChars = get_month_name_c( t->month, 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

M

The month as a number without a leading character

1 to 12

_M

The month as a number with a leading space

1 to 12

MM

The month as a number with a leading zero

01 to 12

MMM

The abbreviated localized month name

Jan to Dec

MMMM

The localized month name

January to December

read_month_c

#define read_month_c_( Sca, Month )                                            \
   read_month_c( (Sca), (Month), "" )
bool read_month_c( cScanner sca[static 1],
                   c_Month month[static 1],
                   char const fmt[static 1] );

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

write_month_c

#define write_month_c_( Rec, Month )                                           \
   write_month_c( (Rec), (Month), "" )
bool write_month_c( cRecorder rec[static 1],
                    c_Month month,
                    char const fmt[static 1] );

Writes a c_Month value into the recorder. The function will use "MMM" as default format.