int main() { printf("%d\n", previous_day(Monday)); printf("%d\n", next_day(Sunday)); printf("%d %d", increment_day(Thursday, 4), increment_day(Monday, -4)); return 0; }
TimeWithDate& TimeWithDate::operator+= (time_t t) { t += this->seconds(); int d = t/SECS_IN_A_DAY; for (int i = 0; i < d; ++i) next_day(); t /= SECS_IN_A_DAY; return *this = TimeWithDate(year, month, day, t); }
void test_date(void) { date d = dateparse("19790729"); assert(d->tm_year==1979); assert(d->tm_mon==7); assert(d->tm_mday==29); assert(!is_leap_year(d)); d->tm_year=2000; assert(is_leap_year(d)); d->tm_year=2004; assert(is_leap_year(d)); d->tm_year=1900; assert(!is_leap_year(d)); d->tm_year=1904; assert(is_leap_year(d)); next_day(d); assert(d->tm_mday == 30); next_day(d); assert(d->tm_mday == 31); next_day(d); assert(d->tm_mday == 1); assert(d->tm_mon == 8); d->tm_mon=2; d->tm_mday=28; next_day(d); assert(d->tm_mday == 29); next_day(d); assert(d->tm_mday == 1); assert(d->tm_mon == 3); d->tm_year=1979; d->tm_mon=2; d->tm_mday=28; next_day(d); assert(d->tm_mday == 1); assert(d->tm_mon == 3); d->tm_year=1979; d->tm_mon=12; d->tm_mday=31; next_day(d); assert(d->tm_mday == 1); assert(d->tm_mon == 1); assert(d->tm_year == 1980); d = dateparse("19770803"); next_day(d); assert(d->tm_year == 1977); assert(d->tm_mon == 8); assert(d->tm_mday == 4); assert(datecmp(dateparse("19770804"), d)==0); assert(datecmp(dateparse("19800101"), dateparse("19790729"))>0); assert(datecmp(dateparse("19330101"), dateparse("19790729"))<0); assert(datecmp(dateparse("19790729"), dateparse("19790729"))==0); }
int main(){ pe_day d; int count = 0; set_start(&d); while (d.year < 2001){ count += (is_counted(&d)) ? 1 : 0; next_day(&d); } printf("%d\n",count); return 0; }
int main(int argc, char* argv[]) { date_t d; int i; d.w = 1; d.d = 1; d.m = 1; d.y = 1900; i = 0; while (d.y < 2001) { if (d.d == 1 && d.w == 0 && d.y >= 1901) { i++; } d = next_day(d); } printf("%d\n", i); return 0; }
void main(int argc, char **argv) { unsigned char *pds, *pds_debug, *gds; FILE *input, *output; int count = 0, yyyymmdd, i; float data[NXNY], factor; /* preliminaries .. open up all files */ if (argc != 4) { fprintf(stderr, "%s [in bin-file] [out gribfile] [YYYYMMDD]\n", argv[0]); exit(8); } if ((input = fopen(argv[1],"rb")) == NULL) { fprintf(stderr,"could not open file: %s\n", argv[1]); exit(7); } if ((output = fopen(argv[2],"wb")) == NULL) { fprintf(stderr,"could not open file: %s\n", argv[2]); exit(7); } yyyymmdd = atoi(argv[3]); printf("initial YYYYMMDD is %d\n", yyyymmdd); /* generate a PDS */ pds = PDStool(New_PDS, /* new PDS */ NCEP_opn, /* center, subcenter */ P_param_table(2), /* parameter table */ P_process(0), /* process that made data */ P_param(PRATE), P_sfc, /* variable and level */ P_date(yyyymmdd), /* initial date yyyymmdd */ P_hour(0), P_ave_dy(0,1), /* averaged from month 0 to 1 */ P_dec_scale(6), /* scale numbers by 10**7 */ P_end); /* end of arguments */ /* generate a GDS */ gds = new_LatLon_GDS(pds,81,51,-140.0,10.0,-60.0,60.0,1.0,1.0); /* loop through all the data */ for (;;) { if (fread(&(data[0]), sizeof(float), NXNY, input) != NXNY) break; factor = 1.0 / 86400.0; for (i = 0; i < NXNY; i++) { if (data[i] == LOCAL_UNDEF) { data[i] = UNDEFINED; } else { data[i] *= factor; } } wrt_grib_rec(pds, gds, data, NXNY, output); /* change date code in the PDS */ yyyymmdd = next_day(yyyymmdd); pds = PDStool(pds, P_date(yyyymmdd),P_end); count++; } free(pds); free(gds); printf("%d records converted\n", count); fclose(input); fclose(output); }