示例#1
0
/*----------------------------------------------------------------------*
 * Convert the given DST change rule to a time_t value                  *
 * for the given year.                                                  *
 *----------------------------------------------------------------------*/
time_t Timezone::toTime_t(TimeChangeRule r, int yr)
{
    tmElements_t tm;
    time_t t;
    uint8_t m, w;            //temp copies of r.month and r.week

    m = r.month;
    w = r.week;
    if (w == 0) {            //Last week = 0
        if (++m > 12) {      //for "Last", go to the next month
            m = 1;
            yr++;
        }
        w = 1;               //and treat as first week of next month, subtract 7 days later
    }

    tm.Hour = r.hour;
    tm.Minute = 0;
    tm.Second = 0;
    tm.Day = 1;
    tm.Month = m;
    tm.Year = yr - 1970;
    t = makeTime(tm);        //first day of the month, or first day of next month for "Last" rules
    t += (7 * (w - 1) + (r.dow - weekday(t) + 7) % 7) * SECS_PER_DAY;
    if (r.week == 0) t -= 7 * SECS_PER_DAY;    //back up a week if this is a "Last" rule
    return t;
}
示例#2
0
inline void page_addSchedule() {
  static schedule s; //Schedule to be added
  static int value = 0;
  if(pre_page != ADD_SCHEDULE) {
    PTLS("Page Add Schedule");
    pre_page = ADD_SCHEDULE; 
    lcd.cursor();
  
    //Need to reintialize everytime we enter the page but not every refresh
    s.day = weekday();
    s.hour = hour();
    s.minute = minute();
    s.temperature = temperature_sensor;
    value = 0;
  }
  String t = getTimeString(s);
  lcd.print(F("Add: "));
  lcd.print(t);
  lcd.setCursor(0,1);
  lcd.print(F("Temp: "));
  lcd.print(s.temperature);
  if (button_input == PLUS_UP || button_input == PLUS_HOLD) {
    if (value == 0) {
      s.day++;
      if (s.day >= 8) s.day = 1;
    } else if (value == 1) {
      s.hour++;
      if (s.hour >= 24) s.hour = 0;
    } else if (value == 2) {
      s.minute++;
      if (s.minute >= 60) s.minute = 0;
    } else if (value == 3) {
      s.temperature++;
      if (s.temperature >= 99) 
        s.temperature = 99;
    }
  }
  else if (button_input == MINUS_UP || button_input == MINUS_HOLD) {
    if (value == 0) {
      s.day--;
      if (s.day <= 0) s.day = 7;
    } else if (value == 1) {
      s.hour--;
      if (s.hour >= 24) s.hour = 23;
    } else if (value == 2) {
      s.minute--;
      if (s.minute >= 60) s.minute = 59;
    } else if (value == 3) {
      s.temperature--;
      if (s.temperature <= 32 || s.temperature >= 99) 
        s.temperature = 32;
    }
  } else if (button_input == MODE_UP)  {
    value += 1;
    value = value % 4;
  } else if (button_input == SET_UP) {
    node_add(s);
    switchPage(LIST_MODE);
  }
}
示例#3
0
static void date_data_func(GtkTreeViewColumn *col,
			   GtkCellRenderer *renderer,
			   GtkTreeModel *model,
			   GtkTreeIter *iter,
			   gpointer data)
{
	int val;
	struct tm *tm;
	time_t when;
	char buffer[40];

	gtk_tree_model_get(model, iter, DIVE_DATE, &val, -1);

	/* 2038 problem */
	when = val;

	tm = gmtime(&when);
	snprintf(buffer, sizeof(buffer),
		"%s, %s %d, %d %02d:%02d",
		weekday(tm->tm_wday),
		monthname(tm->tm_mon),
		tm->tm_mday, tm->tm_year + 1900,
		tm->tm_hour, tm->tm_min);
	g_object_set(renderer, "text", buffer, NULL);
}
示例#4
0
String getTimeString(time_t t = now())
{
  // String holder to return
  String dateStr;
  byte _day = weekday(t);
  byte sub1 = _day * 3;
  byte sub2 = sub1 + 3;
  dateStr = dayShortNames_P.substring(sub1, sub2);
  
  //Example "Sun "
  dateStr.concat(" ");

  int _hour = hour(t);
  if(_hour < 10) {
    dateStr.concat(" ");
  }
  dateStr.concat(_hour); // EX: "Sun 10"
  dateStr.concat(":");  // EX: "Sun 10:"
  
  int _minute = minute(t);
  if(_minute < 10) {
    dateStr.concat("0");
  }
  dateStr.concat(_minute); // EX: "Sun 10:1"
  dateStr.concat(":"); // EX: "Sun 10:1:"
  
  int _second = second(t);
  if(_second < 10) {
    dateStr.concat("0");
  }
  dateStr.concat(_second); // EX: "Sun 10:1:20"
  
  return dateStr;
}
示例#5
0
/* Compute the day number of Easter Sunday in Julian Calendar */
static int
easterodn(int y)
{
	/*
	 * Table for the easter limits in one metonic (19-year) cycle. 21
	 * to 31 is in March, 1 through 18 in April. Easter is the first
	 * sunday after the easter limit.
	 */
	int     mc[] = {5, 25, 13, 2, 22, 10, 30, 18, 7, 27, 15, 4,
		    24, 12, 1, 21, 9, 29, 17};

	/* Offset from a weekday to next sunday */
	int     ns[] = {6, 5, 4, 3, 2, 1, 7};
	date	dt;
	int     dn;

	/* Assign the easter limit of y to dt */
	dt.d = mc[y % 19];

	if (dt.d < 21)
		dt.m = 4;
	else
		dt.m = 3;

	dt.y = y;

	/* Return the next sunday after the easter limit */
	dn = ndaysj(&dt);
	return (dn + ns[weekday(dn)]);
}
示例#6
0
文件: info.c 项目: teni/subsurface
void show_dive_info(struct dive *dive)
{
	struct tm *tm;
	const char *text;
	char buffer[80];

	/* dive number and location (or lacking that, the date) go in the window title */
	tm = gmtime(&dive->when);
	text = dive->location;
	if (!text)
		text = "";
	if (*text) {
		snprintf(buffer, sizeof(buffer), "Dive #%d - %s", dive->number, text);
	} else {
		snprintf(buffer, sizeof(buffer), "Dive #%d - %s %02d/%02d/%04d at %d:%02d",
			dive->number,
			weekday(tm->tm_wday),
			tm->tm_mon+1, tm->tm_mday,
			tm->tm_year+1900,
			tm->tm_hour, tm->tm_min);
	}
	text = buffer;
	if (!dive->number)
		text += 10;     /* Skip the "Dive #0 - " part */
	gtk_window_set_title(GTK_WINDOW(main_window), text);

	SET_TEXT_ENTRY(divemaster);
	SET_TEXT_ENTRY(buddy);
	SET_TEXT_ENTRY(location);
	gtk_text_buffer_set_text(notes, dive && dive->notes ? dive->notes : "", -1);
}
示例#7
0
Date::weekday Date::day_of_week() const {
	// see wikipedia
	static std::array<const int, 12> const t = { { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 } };
    int y=year;
    int m=month;
    y -= m < 3;
    return weekday( (y + y/4 - y/100 + y/400 + t[m-1] + day +6) % 7);
}
示例#8
0
文件: range.c 项目: cbeigong/c
int main()
{
	printf("%s\n",weekday(3));
//	strcpy(week(3),"Fengjie");
	//printf("%s\n",week(3));
	
	showweekday(3);
	return 0;
}
示例#9
0
文件: meetup.c 项目: ozan/solutions
int meetup_day_of_month(int year, int month, char *descriptor, char *day) {
  int offset = offset_for_descriptor(descriptor, year, month);
  int first_weekday = weekday(year, month, offset);
  int target_weekday = weekday_for_day(day);

  if (days_in_month(year, month) < offset)
    return 0;
  return offset + (target_weekday - first_weekday + 7) % 7;
}
void SchedulerJobInstance::calculateNextRunTime() const {
	QDateTime nextRun = runTimeToday();

	nextRun.setDate(QDate::currentDate().addDays( (weekday() + 1) - QDate::currentDate().dayOfWeek() ));
	if (nextRun < QDateTime::currentDateTime()) {
		nextRun = nextRun.addDays(7);
	}
	d->nextRunTime = nextRun;
}
示例#11
0
void loop() {
  delay(250);
  if (now() != prevDisplay) { // update the display only if time has changed
    if (timeStatus() != timeNotSet) {
      DayWeekNumber(year(), month(), day(), weekday());
      digitalClockDisplayLCD();
      prevDisplay = now();
    }
  }
}
示例#12
0
文件: cal.c 项目: tcdog001/autelan
void headers_init(void)
{
  int i, wd;
  char *cur_dh = day_headings, *cur_j_dh = j_day_headings;

  strcpy(day_headings,"");
  strcpy(j_day_headings,"");

#ifdef HAVE_LANGINFO_H
# define weekday(wd)	nl_langinfo(ABDAY_1+wd)
#else
# define weekday(wd)	_time_info->abbrev_wkday[wd]
#endif

  for(i = 0 ; i < 7 ; i++ ) {
     ssize_t space_left;
     wd = (i + weekstart) % 7;

     if (i)
        strcat(cur_dh++, " ");
     space_left = sizeof(day_headings) - (cur_dh - day_headings);
     if(space_left <= 2)
        break;
     cur_dh += center_str(weekday(wd), cur_dh, space_left, 2);

     if (i)
        strcat(cur_j_dh++, " ");
     space_left = sizeof(j_day_headings) - (cur_j_dh - j_day_headings);
     if(space_left <= 3)
        break;
     cur_j_dh += center_str(weekday(wd), cur_j_dh, space_left, 3);
  }

#undef weekday

  for (i = 0; i < 12; i++) {
#ifdef HAVE_LANGINFO_H
     full_month[i] = nl_langinfo(MON_1+i);
#else
     full_month[i] = _time_info->full_month[i];
#endif
  }
}
示例#13
0
/* ----------------------------------------------------------------- */
int congesmobstr(int jy, char string[])
/* ----------------------------------------------------------------- */
{int jm,jd; char st[32];
double tj,rh,rm,rs;
static char *day[7]={"Dim","Lun","Mar","Mer","Jeu","Ven","Sam"};

rh=12.0; rm=rs=0.0;
easter(jy,&jm,&jd);
tj=gregjd(jy,jm,jd,rh,rm,rs)+1.0;
jdgreg(tj,&jy,&jm,&jd,&rh,&rm,&rs);
sprintf(string,"Paques: %04d.%02d.%02d(%s)",jy,jm,jd,day[weekday(tj)]);
tj=gregjd(jy,jm,jd,rh,rm,rs)+38.0;
jdgreg(tj,&jy,&jm,&jd,&rh,&rm,&rs);
sprintf(st," Ascension: %04d.%02d.%02d(%s)",jy,jm,jd,day[weekday(tj)]); strcat(string,st);
tj=gregjd(jy,jm,jd,rh,rm,rs)+11.0;
jdgreg(tj,&jy,&jm,&jd,&rh,&rm,&rs);
sprintf(st," Pentecote: %04d.%02d.%02d(%s)",jy,jm,jd,day[weekday(tj)]); strcat(string,st);
return(0);
}
示例#14
0
static void ServeEventPage(FILE * stream_file)
{
	ServeHeader(stream_file, 200, "OK", false);
	freeMemory();
	const time_t timeNow = nntpTimeServer.LocalNow();
	fprintf_P(stream_file, PSTR("<h1>%d Events</h1><h3>%02d:%02d:%02d %d/%d/%d (%d)</h3>"), iNumEvents, hour(timeNow), minute(timeNow), second(timeNow),
			year(timeNow), month(timeNow), day(timeNow), weekday(timeNow));
	for (uint8_t i = 0; i < iNumEvents; i++)
		fprintf_P(stream_file, PSTR("Event [%02d] Time:%02d:%02d(%d) Command %d data %d,%d<br/>"), i, events[i].time / 60, events[i].time % 60, events[i].time,
				events[i].command, events[i].data[0], events[i].data[1]);
}
示例#15
0
//////////////////////////////////////////////////////////////////////////////////////////////////
// check if system date is valid and send the date header.
//////////////////////////////////////////////////////////////////////////////////////////////////
void ESP8266WebServerEx::sendDateHeader(char* buf) {
  time_t t = now();
  // if time is accurate, then try to send a Date header Wed, 15 Nov 1995 06:25:24 GMT
  if ( year(t)>2015 ) {
    char dow[5];  
    strncpy(dow,dayShortStr(weekday(t)),4);
    dow[3] = 0;
    sprintf(buf,"%s, %02u %s %04u %02u:%02u:%02u GMT",dow,day(t),monthShortStr(month(t)),year(t),hour(t),minute(t),second(t));
    sendHeader("Date",buf);
  } 
}
示例#16
0
QString get_dive_date_string(timestamp_t when)
{
	struct tm tm;
	utc_mkdate(when, &tm);
	return translate("gettextFromC", "%1, %2 %3, %4 %5:%6")
		.arg(weekday(tm.tm_wday))
		.arg(monthname(tm.tm_mon))
		.arg(tm.tm_mday)
		.arg(tm.tm_year + 1900)
		.arg(tm.tm_hour, 2, 10, QChar('0'))
		.arg(tm.tm_min, 2, 10, QChar('0'));
}
示例#17
0
文件: info.c 项目: careychow/diveclog
void update_dive_info(struct dive *dive)
{
	struct tm *tm;
	char buffer[80];
	char *text;

	flush_dive_info_changes();
	buffered_dive = dive;

	if (!dive) {
		gtk_label_set_text(GTK_LABEL(divedate), "no dive");
		gtk_label_set_text(GTK_LABEL(divetime), "");
		gtk_label_set_text(GTK_LABEL(depth), "");
		gtk_label_set_text(GTK_LABEL(duration), "");
		return;
	}

	tm = gmtime(&dive->when);
	snprintf(buffer, sizeof(buffer),
		"%s %02d/%02d/%04d",
		weekday(tm->tm_wday),
		tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900);
	gtk_label_set_text(GTK_LABEL(divedate), buffer);

	snprintf(buffer, sizeof(buffer),
		"%02d:%02d:%02d",
		tm->tm_hour, tm->tm_min, tm->tm_sec);
	gtk_label_set_text(GTK_LABEL(divetime), buffer);

	snprintf(buffer, sizeof(buffer),
		"%d ft",
		to_feet(dive->maxdepth));
	gtk_label_set_text(GTK_LABEL(depth), buffer);

	snprintf(buffer, sizeof(buffer),
		"%d min",
		dive->duration.seconds / 60);
	gtk_label_set_text(GTK_LABEL(duration), buffer);

	*buffer = 0;
	if (dive->watertemp.mkelvin)
		snprintf(buffer, sizeof(buffer),
			"%d C",
			to_C(dive->watertemp));
	gtk_label_set_text(GTK_LABEL(temperature), buffer);

	text = dive->location ? : "";
	gtk_entry_set_text(location, text);
	gtk_label_set_text(GTK_LABEL(locationnote), text);

	text = dive->notes ? : "";
	gtk_text_buffer_set_text(notes, text, -1);
}
示例#18
0
    weekday weekday::operator++(int)
    {
        const int index = m_index;

        if (m_index < 7)
        {
            ++m_index;
        } else {
            m_index = 1;
        }

        return weekday(index);
    }
示例#19
0
    weekday weekday::operator--(int)
    {
        const int index = m_index;

        if (m_index > 1)
        {
            --m_index;
        } else {
            m_index = 7;
        }

        return weekday(index);
    }
示例#20
0
void digitalClockDisplayLCD() {
  // digital clock display of the time
  // Serial /w Debug
  sprintf(buffer, "$FT,Y0,X0#%04d-%02d-%02d ", year(), month(), day());
  Serial.print(buffer);
  sprintf(buffer, "$FT,Y1,X0#%s W%02d D%03d", dow2String(weekday()), WN, DN);
  Serial.print(buffer);
  sprintf(buffer, "$Y5,X0#%02d:%02d:", hour(), minute());
  Serial.print(buffer);
  sprintf(buffer, "$FN,Y5,X35#%02d", second());
  Serial.print(buffer);
  Serial.print(F("$FT#"));
  // I2C LCD
  LcdSetCursor(0, 0);
  sprintf(buffer, "%04d-%02d-%02d %s", year(), month(), day(),
          dow2String(weekday()));
  LcdPrint(buffer);
  sprintf(buffer, "%02d:%02d:%02d W%02d %03d", hour(), minute(), second(), WN,
          DN);
  LcdSetCursor(0, 1);
  LcdPrint(buffer);
}
void loop()
{

	// digital clock display of the time
	sprintf(msg_buff,"%02d:%02d:%02d  %s",hour(),minute(),second(),  dayStr(weekday()));
		sprintf(msg_buff,"%s %d %s %d\r\n",msg_buff, day(),monthStr(month()), year());

	//Send the data
	uart_printf(msg_buff);

	// 1 sec delay
   delay(1000);
}
示例#22
0
文件: DateFormats.cpp 项目: kiuz/Time
/**
 * Display Date and Time with 'hh:mm:ss <CompleteNameDayWeek> dd <CompleteNameMonth> YYYY' format
 */
void longStrFormat_Display(){

	timeComplete_Display();

	Serial.print(" ");
  Serial.print(dayStr(weekday()));
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(monthStr(month()));
  Serial.print(" ");
  Serial.print(year());
}
示例#23
0
void J1ClockKit::Crown::load( tmElements_t &tm ) {
    this->timeElements.Second = tm.Second;
    this->timeElements.Minute = tm.Minute;
    this->timeElements.Hour   = tm.Hour;
    this->timeElements.Day    = tm.Day;
    this->timeElements.Month  = tm.Month;
    this->timeElements.Year   = tm.Year;
    
    time_t t = makeTime( tm );
    this->timeElements.Wday   = weekday( t );
    
    this->field = (tmByteFields) min( max( (int)this->field, (int)tmMinute ), (int)tmYear );
    this->prepare();
}
示例#24
0
void J1ClockKit::Crown::save( tmElements_t &tm ) {
    this->cleanup();
    
    time_t t = makeTime( this->timeElements );
    this->timeElements.Wday = weekday( t );
    
    tm.Second = this->timeElements.Second;
    tm.Minute = this->timeElements.Minute;
    tm.Hour   = this->timeElements.Hour;
    tm.Wday   = this->timeElements.Wday;
    tm.Day    = this->timeElements.Day;
    tm.Month  = this->timeElements.Month;
    tm.Year   = this->timeElements.Year;
}
示例#25
0
文件: Source.c 项目: joniz/Skolgrejer
int main(){
char * monad  = monthName(4);
printf("%s", monad);

 //int leapyear = isLeapYear(1990);
 //printf("%d", leapyear);
 //system("pause");

  char *svar = weekday(0);
  printf("%s", svar);
  system("pause");



}
示例#26
0
EXPORT ER dt_gmtime_us( SYSTIM_U tim_u, struct tm* result )
{
	SYSTIM_U rem = tim_u;
	int d, i, md;

	if (tim_u < 0) {
		return EX_OVERFLOW;
	}

	result->tm_isdst = 0;

	result->tm_usec = (rem % 1000000);
	rem /= 1000000;
	result->tm_sec = (rem % 60);
	rem /= 60;
	result->tm_min = (rem % 60);
	rem /= 60;
	result->tm_hour = (rem % 24);
	rem /= 24;

	d = rem;
	result->tm_wday = weekday(d);

	d += daysbefore1985;
	result->tm_year = -1900 + 1;

	result->tm_year += 400 * (d / days400);
	d %= days400;
	result->tm_year += 100 * (d / days100);
	d %= days100;
	result->tm_year += 4 * (d / days4);
	d %= days4;
	result->tm_year += (d / days1);
	d %= days1;

	result->tm_yday = d;
	for (i = 0; i < 12; i++) {
		md = (i == 1 && isleap(result->tm_year)) ? 29 : _dt_mdays[i];
		if (d < md) {
			break;
		}
		d -= md;
	}

	result->tm_mon = i;
	result->tm_mday = 1 + d;
	return E_OK;
}
示例#27
0
void printTime(time_t t, char *tz) {
    sPrintI00(hour(t));
    sPrintDigits(minute(t));
    sPrintDigits(second(t));
    Serial.print(' ');
    Serial.print(weekday(t));
    Serial.print(' ');
    sPrintI00(day(t));
    Serial.print(' ');
    Serial.print(month(t));
    Serial.print(' ');
    Serial.print(year(t));
    Serial.print(' ');
    Serial.print(tz);
    Serial.println();
}
示例#28
0
/* 
	HTTP response sending a code 200 OK response.
*/
void http_response_ok(FILE *resp, char *cont, int size)
{
	struct tm *st;

	st = get_time();



	fprintf(resp, "HTTP/1.1 200 OK\r\n");
	fprintf(resp, "Date: %s, %i %s %i %i:%i:%i GMT\r\n", weekday(st->tm_wday), 
															st->tm_mday, month(st->tm_mon),
															(st->tm_year + 1900), st->tm_hour,
															st->tm_min, st->tm_sec);
	fprintf(resp, "Content-Type: %s\r\nContent-Length: %i\r\n\r\n", cont, size);
	return;
}
示例#29
0
uint8_t Timer::isSummerTime()
{
	time_t t = mRtc.get() + TIMEZONE_SHIFT_SECONDS;
	
	uint8_t m = month(t);
	
	if(m > 10 || m < 3)
	{
		return 0;
	}
	else if(m > 3 && m < 10)
	{
		return 1;
	}
	else
	{
		uint8_t w = weekday(t);
		
		// otestovat posledni nedeli v mesici
		if(day(t) + 7 - w < 31)
		{
			return m == 3 ? 0 : 1;
		}
		else
		{
			// nedele - otestovat cas
			if(w == 1)
			{
				if(m == 3)
				{
					// brezen po druhe hodine
					return ( hour(t) > 2 ? 1 : 0);
				}
				else
				{
					// rijen po treti hodine
					return ( hour(t) > 2 ? 0 : 1);
					
				}
			}
			else
			{
				return m == 3 ? 1 : 0;
			}
		}
	}
}
示例#30
0
void TimeState::renderClockType1(){
   Serial.println(F("render time type 1"));
  _screen->clearDisplay();
  _screen->setTextSize(5);
  _screen->setCursor(0, 0);
  _screen->setTextWrap(false);
  int8_t hour_time = hour();
  if(hour_time==0)
    hour_time = (uint8_t) 12;
  else if(hour_time>=13)
    hour_time -= (uint8_t) 12;
    
  if(hour_time<=9)
  {
    _screen->setCursor(30, 0);
    _screen->print(hour_time);
  }
  else
    _screen->print(hour_time);
    
  _screen->setCursor(50, 0);
  _screen->print(":");
  _screen->setCursor(70, 0);
  int8_t minute_time = minute();
  
  if(minute_time<=9){ 
    _screen->print("0");
    _screen->setCursor(99, 0);
    _screen->print(minute_time);
  }
  else
    _screen->print(minute_time);
    
    
  _screen->setTextSize(2);

  char *wkdy[7] = {"SUN", "MON", "TUE", "WED", "THR", "FRI", "SAT"};
  _screen->setCursor(5, 43);
  _screen->print(wkdy[weekday()-1]);
  _screen->setCursor(60, 43);
  _screen->print(month());
  _screen->setCursor(78, 43);
  _screen->print("/");
  _screen->setCursor(95, 43);
  _screen->print(day());
  _screen->display();
}