QString WeatherPlugin::replace(const QString &text)
{
    QString res = text;
    QString sun_set, sun_raise, updated;
#if COMPAT_QT_VERSION >= 0x030000
    QTime tmp_time;
    QDateTime dt;
    int h,m;

    parseTime(getSun_set(),h,m);
    tmp_time.setHMS(h,m,0,0);
    sun_set = tmp_time.toString(Qt::LocalDate);
    sun_set = sun_set.left(sun_set.length() - 3);

    parseTime(getSun_raise(),h,m);
    tmp_time.setHMS(h,m,0,0);
    sun_raise = tmp_time.toString(Qt::LocalDate);
    sun_raise = sun_raise.left(sun_raise.length() - 3);

    parseDateTime(getUpdated(),dt);
    updated = dt.toString(Qt::LocalDate);
    updated = updated.left(updated.length() - 3);
#else
    sun_set = getSun_set();
    sun_raise = getSun_raise();
    updated = getUpdated();
#endif
    /* double Expressions *before* single or better RegExp ! */
    res = res.replace(QRegExp("\\%mp"), i18n("moonphase", getMoonPhase()));
    res = res.replace(QRegExp("\\%mi"), number(getMoonIcon()));
    res = res.replace(QRegExp("\\%pp"), number(getPrecipitation()));
	res = res.replace(QRegExp("\\%ut"), i18n("weather", getUV_Description()));
	res = res.replace(QRegExp("\\%ui"), number(getUV_Intensity()));
    res = res.replace(QRegExp("\\%t"), QString::number((int)getTemperature()) + QChar((unsigned short)176) + getUT());
    res = res.replace(QRegExp("\\%f"), QString::number((int)getFeelsLike()) + QChar((unsigned short)176) + getUT());
    res = res.replace(QRegExp("\\%d"), QString::number((int)getDewPoint()) + QChar((unsigned short)176) + getUT());
    res = res.replace(QRegExp("\\%h"), number(getHumidity()) + "%");
    res = res.replace(QRegExp("\\%w"), number(getWind_speed()) + " " + i18n(getUS()));
    res = res.replace(QRegExp("\\%x"), QString::number(getWind_speed() * 10 / 36) + " " + i18n("m/s"));
    res = res.replace(QRegExp("\\%g"), getWindGust() ? QString("(") + i18n("gust ") + number(getWindGust()) + i18n(getUS()) + QString(")") : QString(""));
    res = res.replace(QRegExp("\\%y"), getWindGust() ? QString("(") + i18n("gust ") + number(getWindGust() * 10 / 36) + QString(" ") + i18n("m/s") + QString(")") : QString(""));
    res = res.replace(QRegExp("\\%p"), number(getPressure()) + " " + i18n(getUP()));
    res = res.replace(QRegExp("\\%a"), number(getPressure() * 75 / 100));
    res = res.replace(QRegExp("\\%q"), i18n("weather", getPressureD()));
    res = res.replace(QRegExp("\\%l"), getLocation());
    res = res.replace(QRegExp("\\%b"), i18n("weather", getWind()));
    res = res.replace(QRegExp("\\%u"), updated);
    res = res.replace(QRegExp("\\%r"), sun_raise);
    res = res.replace(QRegExp("\\%s"), sun_set);
    res = res.replace(QRegExp("\\%c"), i18n_conditions(getConditions()));
    res = res.replace(QRegExp("\\%v"), i18n("weather", getVisibility()) + (atol(getVisibility()) ? QString(" ") + i18n(getUD()) : QString("")));
    res = res.replace(QRegExp("\\%i"), number(getIcon()));
    return res;
}
void MoonController::printPhase(int currDay, int currMonth, int currYear) {
  int moonPhase = getMoonPhase(currDay, currMonth, currYear);

  if (moonPhase == 0) {
    digitalWrite(MOON_PIN_0, LOW);
    digitalWrite(MOON_PIN_1, LOW);
    digitalWrite(MOON_PIN_2, LOW);
    digitalWrite(MOON_PIN_3, LOW);
    digitalWrite(MOON_PIN_4, LOW);
    digitalWrite(MOON_PIN_5, LOW);
    digitalWrite(MOON_PIN_6, LOW);
    digitalWrite(MOON_PIN_7, LOW);
  } else if (moonPhase > 0 && moonPhase < 8) {
    digitalWrite(MOON_PIN_0, HIGH);
    digitalWrite(MOON_PIN_1, HIGH);
    digitalWrite(MOON_PIN_2, LOW);
    digitalWrite(MOON_PIN_3, LOW);
    digitalWrite(MOON_PIN_4, LOW);
    digitalWrite(MOON_PIN_5, LOW);
    digitalWrite(MOON_PIN_6, LOW);
    digitalWrite(MOON_PIN_7, LOW);
  } else if (moonPhase == 8) {
    digitalWrite(MOON_PIN_0, HIGH);
    digitalWrite(MOON_PIN_1, HIGH);
    digitalWrite(MOON_PIN_2, HIGH);
    digitalWrite(MOON_PIN_3, HIGH);
    digitalWrite(MOON_PIN_4, LOW);
    digitalWrite(MOON_PIN_5, LOW);
    digitalWrite(MOON_PIN_6, LOW);
    digitalWrite(MOON_PIN_7, LOW);
  } else if (moonPhase > 8 && moonPhase < 15) {
    digitalWrite(MOON_PIN_0, HIGH);
    digitalWrite(MOON_PIN_1, HIGH);
    digitalWrite(MOON_PIN_2, HIGH);
    digitalWrite(MOON_PIN_3, HIGH);
    digitalWrite(MOON_PIN_4, HIGH);
    digitalWrite(MOON_PIN_5, HIGH);
    digitalWrite(MOON_PIN_6, LOW);
    digitalWrite(MOON_PIN_7, LOW);
  } else if (moonPhase == 16) {
    digitalWrite(MOON_PIN_0, HIGH);
    digitalWrite(MOON_PIN_1, HIGH);
    digitalWrite(MOON_PIN_2, HIGH);
    digitalWrite(MOON_PIN_3, HIGH);
    digitalWrite(MOON_PIN_4, HIGH);
    digitalWrite(MOON_PIN_5, HIGH);
    digitalWrite(MOON_PIN_6, HIGH);
    digitalWrite(MOON_PIN_7, HIGH);
  } else if (moonPhase > 16 && moonPhase < 23) {
    digitalWrite(MOON_PIN_0, LOW);
    digitalWrite(MOON_PIN_1, LOW);
    digitalWrite(MOON_PIN_2, HIGH);
    digitalWrite(MOON_PIN_3, HIGH);
    digitalWrite(MOON_PIN_4, HIGH);
    digitalWrite(MOON_PIN_5, HIGH);
    digitalWrite(MOON_PIN_6, HIGH);
    digitalWrite(MOON_PIN_7, HIGH);
  } else if (moonPhase == 24) {
    digitalWrite(MOON_PIN_0, LOW);
    digitalWrite(MOON_PIN_1, LOW);
    digitalWrite(MOON_PIN_2, LOW);
    digitalWrite(MOON_PIN_3, LOW);
    digitalWrite(MOON_PIN_4, HIGH);
    digitalWrite(MOON_PIN_5, HIGH);
    digitalWrite(MOON_PIN_6, HIGH);
    digitalWrite(MOON_PIN_7, HIGH);
  } else if (moonPhase > 24) {
    digitalWrite(MOON_PIN_0, LOW);
    digitalWrite(MOON_PIN_1, LOW);
    digitalWrite(MOON_PIN_2, LOW);
    digitalWrite(MOON_PIN_3, LOW);
    digitalWrite(MOON_PIN_4, LOW);
    digitalWrite(MOON_PIN_5, LOW);
    digitalWrite(MOON_PIN_6, HIGH);
    digitalWrite(MOON_PIN_7, HIGH);
  }
}