Example #1
0
String SparkTime::ISODateString(uint32_t tnow) {
  String ISOString;
  ISOString += yearString(tnow);
  ISOString += "-";
  ISOString += monthString(tnow);
  ISOString += "-";
  ISOString += dayString(tnow);
  ISOString += "T";
  ISOString += hourString(tnow);
  ISOString += ":";
  ISOString += minuteString(tnow);
  ISOString += ":";
  ISOString += secondString(tnow);

  int32_t offset = timeZoneDSTOffset(tnow)/3600L;
  // Guard against timezone problems
  if (offset>-24 && offset<24) { 
    if (offset < 0) {
      ISOString = ISOString + "-" + _digits[-offset] + "00";
    } else {
      ISOString = ISOString + "+" + _digits[offset] + "00";
    }
  }
  return ISOString;
}
Example #2
0
uint32_t SparkTime::year(uint32_t tnow) {
  uint32_t dayNum = (tnow+timeZoneDSTOffset(tnow)-SPARKTIMEBASESTART)/SPARKTIMESECPERDAY;
  uint32_t tempYear = SPARKTIMEBASEYEAR;

  while(dayNum >= YEARSIZE(tempYear)) {
    dayNum -= YEARSIZE(tempYear);
    tempYear++;
  }
  return tempYear;
}
Example #3
0
uint8_t SparkTime::day(uint32_t tnow) {
  uint32_t dayNum = (tnow+timeZoneDSTOffset(tnow)-SPARKTIMEBASESTART)/SPARKTIMESECPERDAY;
  uint32_t tempYear = SPARKTIMEBASEYEAR;
  uint8_t  tempMonth = 0;

  while(dayNum >= YEARSIZE(tempYear)) {
    dayNum -= YEARSIZE(tempYear);
    tempYear++;
  }
  
  while(dayNum >= _monthLength[LEAPYEAR(tempYear)][tempMonth]) {
    dayNum -= _monthLength[LEAPYEAR(tempYear)][tempMonth];
    tempMonth++;
  }
  dayNum++;			// correct for zero-base
  return (uint8_t)dayNum;
}
Example #4
0
uint8_t SparkTime::month(uint32_t tnow) {
  uint32_t dayNum = (tnow+timeZoneDSTOffset(tnow)-SPARKTIMEBASESTART)/SPARKTIMESECPERDAY;
  uint32_t tempYear = SPARKTIMEBASEYEAR;
  uint8_t  tempMonth = 0;

  while(dayNum >= YEARSIZE(tempYear)) {
    dayNum -= YEARSIZE(tempYear);
    tempYear++;
  }
  
  while(dayNum >= _monthLength[LEAPYEAR(tempYear)][tempMonth]) {
    dayNum -= _monthLength[LEAPYEAR(tempYear)][tempMonth];
    tempMonth++;
  }
  tempMonth++;
  return tempMonth;
}
Example #5
0
uint8_t SparkTime::dayOfWeek(uint32_t tnow) {
  uint32_t dayNum = (tnow + timeZoneDSTOffset(tnow)-SPARKTIMEEPOCHSTART)/SPARKTIMESECPERDAY;   
  //Unix epoch day 0 was a thursday
  return ((dayNum+4)%7);
}
Example #6
0
uint8_t SparkTime::second(uint32_t tnow) {
  return ((tnow+timeZoneDSTOffset(tnow)) % 60);
}
Example #7
0
uint8_t SparkTime::minute(uint32_t tnow) {
  uint8_t hTemp = ((tnow+timeZoneDSTOffset(tnow)) % 3600UL)/60UL;
  return hTemp;
//  return (((tnow+timeZoneDSTOffset(tnow)) % 3600) / 60);
}
Example #8
0
uint8_t SparkTime::hour(uint32_t tnow) {
  uint8_t hTemp = ((tnow+timeZoneDSTOffset(tnow)) % 86400UL)/3600UL;
  return hTemp;
}
Example #9
0
uint8_t SparkTime::minute(uint32_t tnow) {
  return (((tnow+timeZoneDSTOffset(tnow)) % 3600) / 60);
}