Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by p5-vbnekit ( 15 years ago )
// ...
#define _date_t_year_width 23
#define _date_t_month_width 4
#define _date_t_day_width 5
// ...
typedef enum _month_t {
_month_t_zero = 0, Jan = 1, Feb = 2, Mar = 3, Apr = 4, May = 5, Jun = 6, Jul = 7, Aug = 8, Sep = 9, Oct = 10, Nov = 11, Dec = 12,
} month_t;
typedef struct _date_t {
unsigned day : _date_t_day_width;
unsigned month : _date_t_month_width;
signed year : _date_t_year_width;
} date_t;
// ...
template <class T> T inline Abs( T n ) {
if ( n < 0 ) return -n; return n;
}
// ...
inline unsigned char DaysInMonth( month_t month, unsigned long int year ) {
switch ( month ) {
case Jan: return 31;
case Feb: if ( ( ( unsigned long int )year % 4 ) ) return 28; return 29;
case Mar: return 31;
case Apr: return 30;
case May: return 31;
case Jun: return 30;
case Jul: return 31;
case Aug: return 31;
case Sep: return 30;
case Oct: return 31;
case Nov: return 30;
case Dec: return 31;
default: return 0;
}
}
inline unsigned short int DaysToMonth( month_t month, unsigned long int year ) {
unsigned short int result = 0;
for ( int i = Jan; i < month; i++ ) result += DaysInMonth( ( month_t )i, year );
return result;
}
// ...
inline bool date_isvalid( signed long int year, unsigned long int month, unsigned long int day ) {
if ( year && month && day
&& Abs( year ) < ( 1 << ( _date_t_year_width - 1 ) )
&& month < 13 && day <= DaysInMonth( ( month_t )month, ( unsigned ) Abs( year ) )
) return true;
return false;
}
Revise this Paste
Parent: 33525
Children: 33530