Ejemplo n.º 1
0
TimeSchedule TimerStringParser::parseWeekly(const Poco::LocalDateTime& now, const std::string& timerString)
{
    const int nowDay = now.dayOfWeek(); // 0 = Sunday, 6 = Saturday
    int sourceDay = extractDay(timerString); // 0 = Sunday, 6 = Saturday

    if(sourceDay < 0)
    {
        LOGE("Invalid day of week in timerString " + timerString);
    }

    if(sourceDay < nowDay) // wait until next week...
        sourceDay += 7;

    int daysToWait = sourceDay - nowDay;

    std::pair<int, int> hourMinutes = parseTime(extractTime(timerString));
    const int hour = hourMinutes.first;
    const int minutes = hourMinutes.second;

    // If the timer runs today, check if it already ran or if it will
    // still run today
    if(daysToWait == 0)
    {
        Poco::LocalDateTime ifToday(
            now.year(),
            now.month(),
            now.day(),
            hour,
            minutes);

        if(ifToday < now)
        {
            LOGI("It's to late to run " + timerString + " today; running next week.");
            daysToWait = 7;
        }
    }

    // At this point, I'd just like to add daysToWait to now and combine
    // this with hour and minutes to know when to run the next time.
    // Unfortunately, unless I'm missing something, this isn't that easy.
    // Since the Poco LocalDateTime and DateTime constructors refuse to do
    // date arithmetic (e.g. day 35 will be somewhere in the next month),
    // I'll have to construct a Timespan that spans the correct number of
    // days, add that to now and then use the day, month & year info in
    // the resulting date. Which can then be combined with hour & minute
    // to find when the next run will be.
    Poco::Timespan daysToWaitTimespan(daysToWait*Poco::Timespan::DAYS);

    Poco::LocalDateTime correctDay = now + daysToWaitTimespan;
    Poco::LocalDateTime correctEverything(
        correctDay.year(),
        correctDay.month(),
        correctDay.day(),
        hour,
        minutes);

    Poco::Timespan wait = correctEverything - now;

    return TimeSchedule(wait, Poco::Timespan(7*Poco::Timespan::DAYS));
}
Ejemplo n.º 2
0
TimeSchedule TimerStringParser::parseDaily(const Poco::LocalDateTime& now, const std::string& timerString)
{
    std::pair<int, int> hourMinutes = parseTime(extractTime(timerString));
    const int hour = hourMinutes.first;
    const int minutes = hourMinutes.second;

    int dayOffset = 0;
    Poco::LocalDateTime ifToday(
        now.year(),
        now.month(),
        now.day(),
        hour,
        minutes);

    if(ifToday < now)
    {
        LOGI("It's to late to run " + timerString + " today; running next week.");
        dayOffset = 1;
    }

    Poco::LocalDateTime tmp(
        now.year(),
        now.month(),
        now.day(),
        hour,
        minutes);

    const Poco::Timespan daysToWaitTimespan(dayOffset*Poco::Timespan::DAYS);
    const Poco::LocalDateTime source = tmp + daysToWaitTimespan;

    const Poco::Timespan wait = source - now;

    return TimeSchedule(wait, Poco::Timespan(1*Poco::Timespan::DAYS));
}
Ejemplo n.º 3
0
//! Get the current date and time as a string.
std::string GetLocalDateTimeString()
{
    Poco::LocalDateTime *time = new Poco::LocalDateTime();
    std::stringstream ss;
    
    ss << std::setw(2) << time->day() << std::setfill('0') << "/" <<
        std::setw(2) << time->month() << std::setfill('0') << "/" <<
        std::setw(4) << time->year() << std::setfill('0') << " " <<
        std::setw(2) << time->hour() << std::setfill('0') << ":" <<
        std::setw(2) << time->minute() << std::setfill('0') << ":" <<
        std::setw(2) << time->second() << std::setfill('0');
    
    SAFE_DELETE(time);
    
    return ss.str();
}
Ejemplo n.º 4
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    Poco::LocalDateTime now; //(2015,5,29,17,38);
    
    if(ofGetKeyPressed(OF_KEY_ALT)) {
        // auto step the time of day to proof changes
        int total_min = fabs(sin(ofGetElapsedTimef()*.05)) * 1440; // 1440 == mins per day  60 * 24
        int hr = floor(total_min/60.0);
        int mn = total_min - (hr*60); //now.minute();
        now.assign(now.year(), now.month(), now.day(), hr, mn);
    }
    
    float sun_brightness = ofxSunCalc::getSunBrightness(todayInfo, now);
    
    if(ofGetKeyPressed(OF_KEY_COMMAND)) {
        sun_brightness = fabs(sin(ofGetElapsedTimef()*.1));
    }
    
    // draw background gradient based on sun_brightness
    
    ofColor nightBG(ofColor::black);
    ofColor nightFG(64);
    
    ofColor dayBG(ofColor::skyBlue);
    ofColor dayFG(ofColor::paleGoldenRod);
    
    ofColor background = nightBG.lerp(dayBG, sun_brightness);
    ofColor foreground = nightFG.lerp(dayFG, sun_brightness);
    
    ofBackgroundGradient(foreground, background);
    
    ofDrawBitmapStringHighlight(date_str, 15, 20, ofColor::paleGoldenRod, ofColor::black);
    
    ofDrawBitmapStringHighlight(min_info_str, 15, 45, ofColor::salmon, ofColor::white);
    
    ofDrawBitmapStringHighlight(max_info_str, 15, 125, ofColor::darkorange, ofColor::white);
    
    ofDrawBitmapStringHighlight(latlon_str, 180, 20, ofColor::gold, ofColor::black);
    
    ofDrawBitmapStringHighlight(pos_str, 180, 45, ofColor::cornsilk, ofColor::black);
    
    ofDrawBitmapStringHighlight("Current Brightness " + ofToString(sun_brightness, 3), 180, 70, ofColor::goldenRod, ofColor::white);
    
    float tx = 10 + 110;
    float ty = 320;
    for(int i = 0; i<timelines.size(); i++) {
        
        ofSetColor(255);
        timelines[i].draw(tx, ty);
        
        ofDrawBitmapStringHighlight(labels[i], 10, ty+13);
        
        if(i == 2) { // today
            ofNoFill();
            ofSetLineWidth(1.0);
            ofSetColor(255);
            ofRect(tx, ty, timelines[i].getWidth(), timelines[i].getHeight());
            
            // Draw a current time mark
            float pixels_per_min = (timelines[i].getWidth() / 24) / 60.0;
            float nx = tx + pixels_per_min * (now.hour() * 60 + now.minute());
            ofSetColor(255, 0, 0);
            ofSetLineWidth(2.0);
            ofLine(nx, ty, nx, ty+timelines[i].getHeight());
        }
        
        ty += timelines[i].getHeight() + 25;
    }
    
}