AceTime  0.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
LocalDateTime.cpp
1 #include "common/util.h"
2 #include "common/DateStrings.h"
3 #include "LocalDateTime.h"
4 
5 namespace ace_time {
6 
7 using common::printPad2;
8 using common::DateStrings;
9 
10 void LocalDateTime::printTo(Print& printer) const {
11  if (isError()) {
12  printer.print(F("<Invalid LocalDateTime>"));
13  return;
14  }
15 
16  // Date
17  printer.print(mLocalDate.year());
18  printer.print('-');
19  printPad2(printer, mLocalDate.month());
20  printer.print('-');
21  printPad2(printer, mLocalDate.day());
22 
23  // 'T' separator
24  printer.print('T');
25 
26  // Time
27  printPad2(printer, mLocalTime.hour());
28  printer.print(':');
29  printPad2(printer, mLocalTime.minute());
30  printer.print(':');
31  printPad2(printer, mLocalTime.second());
32 }
33 
35  if (strlen(dateString) < kDateTimeStringLength) {
36  return LocalDateTime::forError();
37  }
38  return forDateStringChainable(dateString);
39 }
40 
41 
43  const char* s = dateString;
44 
45  // date
47 
48  // 'T'
49  s++;
50 
51  // time
53 
54  dateString = s;
55  return LocalDateTime(ld, lt);
56 }
57 
58 }
59 
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
Definition: LocalTime.h:20
void printTo(Print &printer) const
Print LocalDateTime to &#39;printer&#39; in ISO 8601 format.
static LocalTime forTimeStringChainable(const char *&timeString)
Variant of forTimeString() that updates the pointer to the next unprocessed character.
Definition: LocalTime.cpp:30
static LocalDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
static LocalDate forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
Definition: LocalDate.cpp:69
uint8_t day() const
Return the day of the month.
Definition: LocalDate.h:231
static LocalDateTime forDateString(const char *dateString)
Factory method.
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
uint8_t hour() const
Return the hour.
Definition: LocalTime.h:110
The date (year, month, day) representing the date without regards to time zone.
Definition: LocalDate.h:30
uint8_t minute() const
Return the minute.
Definition: LocalTime.h:116
uint8_t month() const
Return the month with January=1, December=12.
Definition: LocalDate.h:225
int16_t year() const
Return the full year instead of just the last 2 digits.
Definition: LocalDate.h:213
uint8_t second() const
Return the second.
Definition: LocalTime.h:122
LocalDateTime()
Constructor.
bool isError() const
Return true if any component indicates an error condition.