/*! \brief Date of the first day of the first week for a year The first day of a week depends on the current locale ( QLocale::firstDayOfWeek() ). \param year Year \param type Option how to identify the first week \return First day of week 0 \sa QLocale::firstDayOfWeek(), weekNumber() */ QDate QwtDate::dateOfWeek0( int year, Week0Type type ) { const Qt::DayOfWeek firstDayOfWeek = qwtFirstDayOfWeek(); QDate dt0( year, 1, 1 ); // floor to the first day of the week int days = dt0.dayOfWeek() - firstDayOfWeek; if ( days < 0 ) days += 7; dt0 = dt0.addDays( -days ); if ( type == QwtDate::FirstThursday ) { // according to ISO 8601 the first week is defined // by the first thursday. int d = Qt::Thursday - firstDayOfWeek; if ( d < 0 ) d += 7; if ( dt0.addDays( d ).year() < year ) dt0 = dt0.addDays( 7 ); } return dt0; }
void setDate(void) { DateTime dt0(rtc.now()); int year; int month; int day; int res; myScreen.Panels->BigTime->Hide(); String newtime = myScreen.Keyboard( PSTR("Enter DD/MM[/YY]"),KBPHONE); myScreen.Panels->BigTime->Show(); /* dbgprint("Current time : Year: ");dbgprint(dt0.year()); dbgprint(" Month: ");dbgprint(dt0.month()); dbgprint(" Day: ");dbgprint(dt0.day()); dbgprint(" Hour: ");dbgprint(dt0.hour()); dbgprint(" Minute: ");dbgprint(dt0.minute()); dbgprint(" Second: ");dbgprintln(dt0.second());*/ res = sscanf(newtime.c_str(),"%2u/%2u/%2u",&day,&month,&year); if ((month < 13)&&(day<32)) { if (res ==3) { year +=2000; dbgprint(PSTR("date 3: ")+newtime);dbgprint(PSTR(" Year "));dbgprint(year);dbgprint(PSTR(" Month "));dbgprint(month);dbgprint(PSTR(" Day "));dbgprintln(day); rtc.adjust(DateTime(year,month,day,dt0.hour(),dt0.minute(),dt0.second())); } else if (res == 2) { dbgprint(PSTR("date 4: ")+newtime);dbgprint(PSTR(" Year "));dbgprint(dt0.year());dbgprint(PSTR(" Month "));dbgprint(month);dbgprint(PSTR(" Day "));dbgprintln(day); rtc.adjust(DateTime(dt0.year(),month,day,dt0.hour(),dt0.minute(),dt0.second())); } } }
void setTime(void) { DateTime dt0(rtc.now()); int hour; int min; int sec =0; int res; myScreen.Panels->BigTime->Hide(); String newtime = myScreen.Keyboard( PSTR("Enter HH:MM[:SS]"),KBPHONE); myScreen.Panels->BigTime->Show(); /* dbgprint(PSTR("Current time : Year: "));dbgprint(dt0.year()); dbgprint(PSTR(" Month: "));dbgprint(dt0.month()); dbgprint(PSTR(" Day: "));dbgprint(dt0.day()); dbgprint(PSTR(" Hour: "));dbgprint(dt0.hour()); dbgprint(PSTR(" Minute: "));dbgprint(dt0.minute()); dbgprint(PSTR(" Second: "));dbgprintln(dt0.second());*/ res = sscanf(newtime.c_str(),"%2u:%2u:%2u",&hour,&min,&sec) ; if ((hour < 24)&&(min < 60)&&(sec<60)) { if ((res == 3) || (res == 2)) { dbgprintln(PSTR("time 3: ")+newtime); rtc.adjust(DateTime(dt0.year(),dt0.month(),dt0.day(),hour,min,sec)); } } }
void TimeInt() { char ci[10] ; DateTime dt0(rtc.now()); myScreen.ESecond.TrigOn(); sprintf(ci,"%02d:%02d:%02d", dt0.hour(),dt0.minute(),dt0.second()); myScreen.StatusBar->Status[3]->Caption(ci); }
KStarsDateTime modCalcEquinox::findEquinox( int year, bool Spring, KPlotObject *ecl ) { // Interpolate to find the moment when the Sun crosses the equator // Set initial guess in February or August to be sure that this // point is before equinox. const int month = Spring ? 2 : 8; int i = QDate( year, month, 1 ).dayOfYear(); double dec1, dec2; dec2 = ecl->points()[i]->y(); do { ++i; dec1 = dec2; dec2 = ecl->points()[i]->y(); } while ( dec1*dec2 > 0.0 ); //when dec1*dec2<0.0, we bracket the zero double x1 = ecl->points()[i-1]->x(); double x2 = ecl->points()[i]->x(); double d = fabs(dec2 - dec1); double f = 1.0 - fabs(dec2)/d; //fractional distance of the zero, from point1 to point2 KStarsDateTime dt0( QDate( year, 1, 1 ), QTime(0,0,0) ); KStarsDateTime dt = dt0.addSecs( 86400.0*(x1-1 + f*(x2-x1)) ); return dt; }
void TBigTime::Draw() { // dbgprintln("TBigTime draw"); char ci[24] ,ct[8]; uint16_t atx; if (!active) return; if (!isDisplayed()) { Parent->fillRect(0,top,WIDTH,HEIGHT-LHEIGHT,color) ; Parent->drawRect(0,top,WIDTH,HEIGHT-LHEIGHT,ILI9341_WHITE) ; displayed = true; // return; } DateTime dt0(rtc.now()); Parent->setTextColor(ILI9341_WHITE); Parent->setFont(fixednums15x31); Parent->setTextArea(0, 0, WIDTH, HEIGHT); sprintf(ci,"%02d:%02d:%02d", dt0.hour(),dt0.minute(),dt0.second()); Parent->fillRect (WIDTH/2 -((fixednums15x31[2]*strlen(ci))/2 ),HEIGHT/3,fixednums15x31[2]*(strlen(ci)+1),fixednums15x31[3],color) ; Parent->printAt(ci,WIDTH/2 -((fixednums15x31[2]*strlen(ci))/2 ),HEIGHT/3); Parent->setFont(Arial_bold_14); sprintf(ci,"%02d/%02d/%04d", dt0.day(),dt0.month(),dt0.year()); atx = WIDTH/2 -((Arial_bold_14[2]*strlen(ci))/2 ); Parent->fillRect (atx,(HEIGHT/3) +50,Arial_bold_14[2]*(strlen(ci)+1),Arial_bold_14[3],color) ; Parent->printAt(ci,atx,(HEIGHT/3) +50); rtc.readTemperature(ct); sprintf(ci,"%s Celsius",ct); Parent->fillRect (atx,(HEIGHT/3) +80,Arial_bold_14[2]*(strlen(ci)+1),Arial_bold_14[3],color) ; Parent->printAt(ci,atx,(HEIGHT/3) +80); Parent->setTextColor(ILI9341_GRAY); if (!Options.isActive()) Parent->printAt("Set: touch here",4*WIDTH/8 ,(HEIGHT-30)); }
CDialogHistoryAll::CDialogHistoryAll( const wxDateTime *pCurrentSelection, COARfile *pFile, wxWindow *parent, wxWindowID id) : wxDialog( parent, id, g_TITLE, wxDefaultPosition, g_SIZE, mainApp::DIALOG_STYLE), m_timeSelected((time_t)1), m_pTimeSelected(NULL) { const set<wxDateTime> *psetHistory = pFile->GetHistory(); wxArrayString asTime; int nSelect = 0; if(pCurrentSelection != NULL) { m_timeSelected = *pCurrentSelection; m_pTimeSelected = &m_timeSelected; } asTime.Alloc(psetHistory->size() + 3); asTime.Add(_T("Current")); m_vTime.reserve(psetHistory->size() + 1); for(set<wxDateTime>::const_reverse_iterator itr = psetHistory->rbegin(); itr != psetHistory->rend(); ++itr) { if(_AppendTime(&asTime,*itr)) { nSelect = (int) m_vTime.size(); } } const wxDateTime &dtBegin(pFile->GetCreationTime()); size_t nSize = m_vTime.size(); if(nSize && (dtBegin < m_vTime.at(nSize - 1))) { if(_AppendTime(&asTime,dtBegin)) { nSelect = (int) m_vTime.size(); } } if(nSize) { wxDateTime dt0((time_t)0); if(_AppendTime(&asTime,dt0)) { nSelect = (int) m_vTime.size(); } } // now build it and they will look m_pList = new wxListBox(this,wxID_ANY, wxDefaultPosition, wxDefaultSize, asTime,wxLB_SINGLE | wxLB_NEEDED_SB); m_pList->Select(nSelect); wxBoxSizer *pSizer(new wxBoxSizer(wxVERTICAL)); pSizer->Add(m_pList,1,wxALL | wxEXPAND, ID_BORDER); pSizer->Add( CreateButtonSizer(wxOK | wxCANCEL), 0,(wxALL ^ wxTOP) | wxALIGN_CENTRE,ID_BORDER); SetSizer(pSizer); pSizer->Layout(); }
void create_point_test() { // create point with specified parameterization { piecewise_curve_type pc; point_creator_type pt_creator(4); data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1), dt; point_type p0, ptemp; // set the point p0 << 1, 2, 3; pt_creator.set_point(p0); // set the times pt_creator.set_t0(t0); pt_creator.set_segment_dt(dt0, 0); pt_creator.set_segment_dt(dt1, 1); pt_creator.set_segment_dt(dt2, 2); pt_creator.set_segment_dt(dt3, 3); // test point setting ptemp=pt_creator.get_point(); TEST_ASSERT(p0==ptemp); // test time step settings TEST_ASSERT(pt_creator.get_t0()==t0); dt=pt_creator.get_segment_dt(0); TEST_ASSERT(dt==dt0); dt=pt_creator.get_segment_dt(1); TEST_ASSERT(dt==dt1); dt=pt_creator.get_segment_dt(2); TEST_ASSERT(dt==dt2); dt=pt_creator.get_segment_dt(3); TEST_ASSERT(dt==dt3); // create the polygon TEST_ASSERT(pt_creator.create(pc)); } // create point with default parameterization { piecewise_curve_type pc; point_creator_type pt_creator(4); data_type dt; point_type p0, ptemp; // set the corners p0 << 1, 0, 0; pt_creator.set_point(p0); // test corner settings ptemp=pt_creator.get_point(); TEST_ASSERT(p0==ptemp); // test time step settings TEST_ASSERT(pt_creator.get_t0()==0); dt=pt_creator.get_segment_dt(0); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(1); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(2); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(3); TEST_ASSERT(dt==1); // create the polygon TEST_ASSERT(pt_creator.create(pc)); } }