logincheck() { if ( thisAccount.special[ hour() ] ) /* Is is free time? */ { specialTime = TRUE; } else { specialTime = FALSE; } /* Local and bad calls get no accounting. */ if (!gotCarrier() || (whichIO == CONSOLE)) return(TRUE); if ( !thisAccount.days[ dayofweek() ] || !thisAccount.hours[ hour() ] || logBuf.credits <= 0 ) { tutorial("nologin.blb"); loggedIn = FALSE; terminate(TRUE, FALSE); return (FALSE); } if ( thisAccount.special[ hour() ] ) /* Is is free time? */ { specialTime = TRUE; } return (TRUE); }
int main() { switch(dayofweek(2014,3,25)) { case 0 : printf("7"); break ; case 1 : printf("1"); break ; case 2 : printf("2"); break ; case 3 : printf("3"); break ; case 4 : printf("4"); break ; case 5 : printf("5"); break ; case 6 : printf("6"); break ; } getchar(); return 0 ; }
static void weekofyear(int year,int month,int day, int *rtn_year,int *rtn_week,int *rtn_day) { int firstday=dayofweek(year,0,0); int doy=dayofyear(year,month,day); if(firstday>=5) { firstday-=7; if(firstday+doy<0) { weekofyear(year-1,12-1,31-1, rtn_year,rtn_week,rtn_day); *rtn_day+=doy+1; return; } } if(firstday!=4 && (firstday+doy)/7>=52) { *rtn_year=year+1; *rtn_week=0; *rtn_day=(firstday+doy)-52*7; } else { *rtn_year = year; *rtn_week = (firstday+doy)/7; *rtn_day = (firstday+doy)%7; } }
void C_PrintCompileDate(void) { int day, month, year, hour, minute; static const char *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; static const char mths[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; static const char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; static char mth[4]; sscanf(__DATE__, "%3s %2d %4d", mth, &day, &year); sscanf(__TIME__, "%2d:%2d:%*d", &hour, &minute); month = (strstr(mths, mth) - mths) / 3; C_Printf(""); C_Printf(" This %i-bit %s binary of %s was built on %s, %s %i, %i at %i:%02i%s\n", (sizeof(intptr_t) == 4 ? 32 : 64), "Linux", PACKAGE_NAMEANDVERSIONSTRING, days[dayofweek(day, month + 1, year)], months[month], day, year, (hour > 12 ? hour - 12 : hour), minute, (hour < 12 ? "am" : "pm")); }
caddr_t bif_dayofweek (caddr_t * qst, caddr_t * err_ret, state_slot_t ** args) { caddr_t arg = bif_date_arg (qst, args, 0, "dayofweek"); return box_num (dayofweek (arg)); }
/* Driver function to test above function */ int main() { int check=0; int day = dayofweek(23, 8, 2015); check--; printf("%d %d", day,check); return 0; }
void printdate1(char *buf,const char *date) { int year; int month; int day; int dow; buf[0]=0; if(!date[0]) return; numericdate(date,&year,&month,&day); dow=dayofweek(year,month,day); sprintf(buf,"%s %s %d",days[dow],months[month],day+1); }
void ReadingPlanWizardDatesPage::UpdateDays() { RPDate currDay = m_dateBegin; m_intTotalDays = 0; int intTotalSpan = m_dateEnd - m_dateBegin + 1; int intThisDay; wxString caption; if(intTotalSpan > 0) { for( int count = 0; count < intTotalSpan; count++) { intThisDay = dayofweek(currDay.getDay(), currDay.getMonth(), currDay.getYear()); switch(intThisDay) { case 0: if(m_ckSunday->IsChecked()) m_intTotalDays++; break; case 1: m_intTotalDays++; break; case 2: if(m_ckTuesday->IsChecked()) m_intTotalDays++; break; case 3: if(m_ckWednesday->IsChecked()) m_intTotalDays++; break; case 4: if(m_ckThursday->IsChecked()) m_intTotalDays++; break; case 5: if(m_ckFriday->IsChecked()) m_intTotalDays++; break; case 6: if(m_ckSaturday->IsChecked()) m_intTotalDays++; break; } currDay.advanceDate(1); } caption.Printf(wxT(" %d"), m_intTotalDays); m_lblDayTotal->SetLabel(_("Total Days:") + caption); } else { m_lblDayTotal->SetLabel(_("Total Days:") + wxString(wxT(" 0"))); } }
int main(int argc, char const *argv[]) { char birthday[100]; printf("What is yout birthday (format: DDMMYYYY) : "); scanf("%s", birthday); if (!validate(birthday)) { printf("Your input is invalid.\n"); return -1; } int day = get_day_from_DDMMYYYY(birthday); int month = get_month_from_DDMMYYYY(birthday); int year = get_year_from_DDMMYYYY(birthday); int week_index = dayofweek(day,month,year); printf("The %i/%i/%i is a %s.\n", day, month, year, week[week_index]); printf("The following 5 years on which the %i/%i falls on a %s are:\n", day, month, week[week_index]); int i; int tmp_year = year + 1; for (i = 0; i < 5; tmp_year++) { if (dayofweek(day, month, tmp_year) == week_index) { printf("%i\n", tmp_year); i++; } } return 0; }
void printdate1w(char *buf,const char *date) { int year; int month; int day; int dow; int yr; int wkn; int dny; buf[0]=0; if(!date[0]) return; numericdate(date,&year,&month,&day); dow=dayofweek(year,month,day); weekofyear(year,month,day,&yr,&wkn,&dny); sprintf(buf,"%s %s %d wk%d",days[dow],months[month],day+1,wkn+1); }
static void html_output_month_cal(struct buffer *pdst, idx_msgnum_t *mn, unsigned int y, unsigned int m, html_date_level_t level) { unsigned int d; idx_msgnum_t mp, count; /* "Monday is the first day of the week according to the international standard ISO 8601" */ enum { SUNDAY, MONDAY } weekstart = MONDAY; buffer_appendf(pdst, "\n<table border=0 class=cal_mon><tr>%s<th>Mon<th>Tue<th>Wed<th>Thu<th>Fri<th>Sat%s", weekstart == SUNDAY ? "<th>Sun" : "", weekstart == MONDAY ? "<th>Sun" : ""); int leapyear = y % 4 || (y % 100 == 0 && y % 400) ? 0 : 1; int daysinmonth = m == 2 ? 28 + leapyear : 31 - (m - 1) % 7 % 2; int firstday = dayofweek(y, m, 1); mp = mn[0]; for (d = 1; d <= daysinmonth; d++) { unsigned int col = (7 + d + firstday - weekstart - 1) % 7; if (d == 1 || col == 0) buffer_appends(pdst, "\n<tr>"); if (d == 1 && col > 0) buffer_appendf(pdst, "<td colspan=\"%u\">", col); buffer_appendf(pdst, "<td><sup>%u</sup> ", d); if (mn[d]) { if (mp > 0) { if (mn[d] > 0) count = mn[d] - mp; else count = -mn[d]; if (count <= 0) return; buffer_appends(pdst, "<a href=\""); if (level <= L_MONTHLY) buffer_appendf(pdst, "%02u/", m); buffer_appendf(pdst, "%02u/\">%u</a>", d, count); } mp = mn[d]; } if (d == daysinmonth && 7 - col - 1 > 0) buffer_appendf(pdst, "<td colspan=\"%u\">", 7 - col - 1); } buffer_appends(pdst, "\n</table>\n"); }
int main(void) { int y, m, d, w; char *ws[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; printf("weekday request. \n"); printf("year:"); scanf("%d", &y); printf("month:"); scanf("%d", &m); printf("day:"); scanf("%d", &d); w = dayofweek(y, m, d); if(w != -1) printf("that is %s. \n", ws[w]); else printf("can not take it. \n"); return (0); }
static int mailimf_date_time_write(FILE * f, int * col, struct mailimf_date_time * date_time) { int r; char date_str[MAX_DATE_STR]; #if 0 struct tm tmval; time_t timeval; #endif int wday; #if 0 tmval.tm_sec = date_time->sec; tmval.tm_min = date_time->min; tmval.tm_hour = date_time->hour; tmval.tm_sec = date_time->sec; tmval.tm_mday = date_time->day; tmval.tm_mon = date_time->month - 1; tmval.tm_year = date_time->year - 1900; tmval.tm_isdst = 1; timeval = mktime(&tmval); localtime_r(&timeval, &tmval); #endif wday = dayofweek(date_time->dt_year, date_time->dt_month, date_time->dt_day); snprintf(date_str, MAX_DATE_STR, "%s, %i %s %i %02i:%02i:%02i %+05i", week_of_day_str[wday], date_time->dt_day, month_str[date_time->dt_month - 1], date_time->dt_year, date_time->dt_hour, date_time->dt_min, date_time->dt_sec, date_time->dt_zone); r = mailimf_string_write(f, col, date_str, strlen(date_str)); if (r != MAILIMF_NO_ERROR) return r; return MAILIMF_NO_ERROR; }
static void diary_set_calendar_info(calendar_info *cal, const char *querystr) { time_t t; struct tm *tm, *tm_today, tm_cal = {0}; char buf[12]; const int dayofmonthes[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; char calyear[5] = {'\0'}; char calmonth[3] = {'\0'}; int year, month; /* Setup today */ t = time(NULL); tm_today = localtime(&t); strftime(buf, 11, "%Y-%m-%d", tm_today); strcpy(cal->today, buf); /* Setup calendar month */ if (querystr != NULL) { strncpy(calyear, querystr + 8, 4); strncpy(calmonth, querystr + 12, 2); year = atoi(calyear); month = atoi(calmonth); if (validate_year_and_month(year, month) >= 0) { tm_cal.tm_year = year - 1900; tm_cal.tm_mon = month; t = mktime(&tm_cal); } } /* Setup the calendar data */ tm = localtime(&t); cal->year = tm->tm_year + 1900; strcpy(cal->month, calmonth); cal->lastdayofmonth = dayofmonthes[tm->tm_mon]; if(tm->tm_mon == 1 /* Feb */ && cal->year%4 == 0 && (cal->year%100 != 0 || cal->year%400 == 0)) ++cal->lastdayofmonth; sprintf(cal->month, "%02d", tm->tm_mon + 1); sprintf(cal->day, "%02d", tm->tm_mday); /* Get the day of week of the 1st day of this month */ cal->dayofweek_1stdayofmonth = dayofweek(cal->year, tm->tm_mon, 1); }
/** * Convert the date and time data of the nmeaINFO structure * to a RTCDateTime structure for use in ChibiOS * * @param info a pointer to the structure * @param timespec a pointer to the RTCDateTime structure */ void nmea_INFO2time(nmeaINFO *info, RTCDateTime *timespec, long int timezone) { timespec->year = (uint32_t)info->utc.year - (1980U - 1900U); timespec->month = (uint32_t)info->utc.mon + 1U; timespec->day = (uint32_t)info->utc.day; timespec->dayofweek = (uint32_t)dayofweek((int)timespec->year + 1980, (int)timespec->month, (int)timespec->day); if (timespec->dayofweek == 0) timespec->dayofweek = RTC_DAY_SUNDAY; timespec->dstflag = 0U; /* set zero if dst is unknown */ timespec->millisecond = (uint32_t)(info->utc.hsec * 10) + (uint32_t)( ( (info->utc.hour * 3600) + (info->utc.min * 60) + (info->utc.sec) ) * 1000); timespec->millisecond += (timezone * 1000); if (timespec->millisecond > NMEA_MILLIS_IN_DAY) { timespec->day++; timespec->millisecond -= - NMEA_MILLIS_IN_DAY; } else if ((timespec->millisecond + (timezone * 1000)) < 0) { timespec->day--; timespec->millisecond += NMEA_MILLIS_IN_DAY; } }
static void diary_set_calendar_info(calendar_info *cal) { time_t now; struct tm *tm; char buf[12]; const int dayofmonthes[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* Setup the calendar data */ now = time(NULL); tm = localtime(&now); cal->year = tm->tm_year + 1900; cal->lastdayofmonth = dayofmonthes[tm->tm_mon]; if(tm->tm_mon == 1 /* feb */ && cal->year%4 == 0 && (cal->year%100 != 0 || cal->year%400 == 0)) ++cal->lastdayofmonth; sprintf(cal->month, "%02d", tm->tm_mon + 1); sprintf(cal->day, "%02d", tm->tm_mday); strftime(buf, 11, "%Y-%m-%d", tm); strcpy(cal->today, buf); /* Get the day of week of the 1st day of this month */ cal->dayofweek_1stdayofmonth = dayofweek(cal->year, tm->tm_mon, 1); }
/** * render_date: Render date nicely. * @vr: The #VirguleReq context. * @iso: The date in ISO format (YYYY-MM-DD) * @showtime: 0 = date only, 1 = date + time, 2 = date + time (RFC 822) * * Return value: Nicely formatted date string. **/ char * virgule_render_date (VirguleReq *vr, const char *iso, int showtime) { int year, month, day; char *hhmm; const char *months[] = { "Nilember", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; if (strlen (iso) < 10 || iso[4] != '-' || iso[7] != '-') return "--error--"; year = atoi (iso); month = atoi (iso + 5); day = atoi (iso + 8); if (showtime == 3) { return apr_psprintf (vr->r->pool, "%d %s %02d", year, months[month], day); } if (showtime == 2) { hhmm = apr_pstrndup (vr->r->pool, iso + 11, 8); return apr_psprintf (vr->r->pool, "%s, %d %s %d %s %s", days[dayofweek(day,month,year)], day, months[month], year, hhmm, "GMT"); } if (showtime == 1) { hhmm = apr_pstrndup (vr->r->pool, iso + 11, 5); return apr_psprintf (vr->r->pool, "%d %s %d at %s %s", day, months[month], year, hhmm, "UTC"); } return apr_psprintf (vr->r->pool, "%d %s %d", day, months[month], year); }
/* governing function, calls others */ int process_date(char *s,struct tm *thetime,int usesymm) { int i,j,k; int month; k = parse_for_year(s,thetime); if (k == 0) { thetime->tm_mon = 0; thetime->tm_mday = 1; } month = parse_for_alpha_month(s,thetime); if (month == -1) month = parse_for_hyphen_month(s,thetime); if (month == -1) month = parse_for_slash_month(s,thetime); if (month < 0) i = parse_for_weekday(s,thetime); j = parse_sexa_time(s,thetime); if (j == -1) j = parse_tgm_time(s,thetime); if (month == -1 && i == -1 && j == -1) { thetime->tm_mon = 0; thetime->tm_mday = 1; } else if (month >= 0) { thetime->tm_mon = month; } if ((usesymm == NEITHER) || (usesymm == OUT)) { thetime->tm_wday = dayofweek(thetime->tm_year+1900, thetime->tm_mon+1,thetime->tm_mday); thetime->tm_yday = ydays_from_date(thetime); } if ((usesymm == IN) || (usesymm == BOTH)) { } else errorcheck(s,thetime); return 0; }
/* ensures that weekday given matches the dates, etc., * specifically for the symmetry calendar */ int symm_errorcheck(char *s, struct tm *thetime) { char *weekday, *oweekday; char *month; char number[SIZE]; int i; /* verify that year is an acceptable value */ if (thetime->tm_year+1900 > 2699 || thetime->tm_year+1900 < 1700) { fprintf(stderr,"dozdate: error: year is too large; " "only dates between 0E98 and 168E\ncan be " "calculated\n"); exit(BAD_YEAR); } /* fill some useful variables for error-checking */ for (i=0; thetime->tm_wday != weekdays[i].num; ++i); weekday = weekdays[i].longname; oweekday = weekdays[dayofweek(thetime->tm_year+1900, thetime->tm_mon+1,thetime->tm_mday)].longname; for (i=0; thetime->tm_mon != months[i].num; ++i); month = months[i].longname; /* check for mday error */ if ((thetime->tm_mon == 0 && thetime->tm_mday > 30) || (thetime->tm_mon == 1 && thetime->tm_mday > 31) || (thetime->tm_mon == 2 && thetime->tm_mday > 30) || (thetime->tm_mon == 3 && thetime->tm_mday > 30) || (thetime->tm_mon == 4 && thetime->tm_mday > 31) || (thetime->tm_mon == 5 && thetime->tm_mday > 30) || (thetime->tm_mon == 6 && thetime->tm_mday > 30) || (thetime->tm_mon == 7 && thetime->tm_mday > 31) || (thetime->tm_mon == 8 && thetime->tm_mday > 30) || (thetime->tm_mon == 9 && thetime->tm_mday > 30) || (thetime->tm_mon == 10 && thetime->tm_mday > 31) || (thetime->tm_mon == 11 && thetime->tm_mday > 30) || (thetime->tm_mon == 12 && thetime->tm_mday > 7)) { dectodoz(number,(double)thetime->tm_mday); fprintf(stderr,"dozdate: error: %s does not have " "%s days\n",month,number); exit(BAD_MDAY); } else if ((thetime->tm_mon == 1) && (thetime->tm_mday == 29)) { if (!leapyear(0,thetime->tm_year+1900)) { dectodoz(number,(double)thetime->tm_year+1900); fprintf(stderr,"dozdate: error: %s is not a " "leap year\n",number); exit(BAD_LEAP_YEAR); } } /* check for weekday error; fix if necessary */ if (thetime->tm_wday != dayofweek(thetime->tm_year+1900, thetime->tm_mon+1,thetime->tm_mday)) { if (strstr(s,"Sun") || strstr(s,"Mon") || strstr(s,"Tue") || strstr(s,"Wed") || strstr(s,"Thu") || strstr(s,"Fri") || strstr(s,"Sat")) fprintf(stderr,"dozdate: weekday \"%s\" does not " "match the date \"%d %s %d\";\nsetting to the correct " "weekday, \"%s\"\n",weekday,thetime->tm_mday, month,thetime->tm_year+1900,oweekday); thetime->tm_wday = dayofweek(thetime->tm_year+1900, thetime->tm_mon+1,thetime->tm_mday); } if (thetime->tm_hour > 23) { fprintf(stderr,"dozdate: error: hour is too " "large\n"); exit(BAD_HOUR); } if (thetime->tm_min > 59) { fprintf(stderr,"dozdate: error: minute is too " "large\n"); exit(BAD_MIN); } if (thetime->tm_sec > 60) { fprintf(stderr,"dozdate: error: second is too " "large\n"); exit(BAD_SEC); } return 0; }
void updatebalance(void) { double drain; long timestamp, diff; if (thisAccount.special[hour()] && !specialTime) { specialTime = TRUE; doCR(); if (loggedIn) { mPrintf("Free time is now beginning, you have no time limit."); doCR(); } } /* if it's no longer special time.... */ if (specialTime && !thisAccount.special[hour()]) { doCR(); if (loggedIn) { mPrintf("Free time is over. You have %.0f %s%s left today.", cfg.credit_name, logBuf.credits, (logBuf.credits == 1) ? "" : "s"); doCR(); } specialTime = FALSE; lasttime=cit_time(); } if (specialTime) /* don't charge them for FREE time! */ return; /* get current time stamp */ timestamp=cit_time(); diff = timestamp - lasttime; /* If the time was set wrong..... */ if (diff < 0) diff = 0; drain = (double) diff / 60.0; logBuf.credits = logBuf.credits - (float) drain; lasttime=cit_time(); if (!gotCarrier() || onConsole) return; if (logBuf.credits < 5.0) { doCR(); mPrintf(" Only %.0f %s%s left today!", logBuf.credits, cfg.credit_name, ((int) logBuf.credits == 1) ? "" : "s"); doCR(); } if (!thisAccount.days[dayofweek()] /* if times up of it's no */ ||!thisAccount.hours[hour()] /* login time for them.. */ ||logBuf.credits <= 0.0) { nextblurb("goodbye", &(cfg.cnt.gcount), 1); terminate(TRUE, 1); } }
static int getdfw(int year) { int d=dayofweek(year,0,0); if(d>4) return 7-d; else return -d; }
void updatebalance(void) { float drain; long timestamp, diff; if ( thisAccount.special[ hour() ] && !specialTime) { specialTime = TRUE; doCR(); if (loggedIn) { mPrintf("Special time is now beginning, you have no time limit."); doCR(); } } if (specialTime && /* if it's no longer special */ !thisAccount.special[ hour() ] ) /* time.... */ { doCR(); if(loggedIn) { mPrintf("Special time is over. You have %.0f %s left today.", logBuf.credits, (logBuf.credits == 1)?"minute":"minutes" ); doCR(); } specialTime = FALSE; time(&lasttime); } if (specialTime) /* don't charge them for FREE time! */ return; /* get current time stamp */ time(×tamp); diff = timestamp - lasttime; /* If the time was set wrong..... */ if (diff < 0) diff = 0; drain = (float)((float)diff / (float)60); logBuf.credits = logBuf.credits - drain; time(&lasttime); if (!gotCarrier() || (whichIO == CONSOLE)) return; if (logBuf.credits < (float)5) { doCR(); mPrintf(" Only %.0f %s left today!", logBuf.credits, (logBuf.credits == 1)?"minute":"minutes" ); doCR(); } if ( !thisAccount.days[ dayofweek() ] /* if times up of it's no */ || !thisAccount.hours[ hour() ] /* login time for them.. */ || logBuf.credits <= (float)0 ) { tutorial("goodbye.blb"); terminate(TRUE, 1); } }