AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized 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  // Week day
34  DateStrings ds;
35  printer.print(ds.weekDayLongString(dayOfWeek()));
36 }
37 
39  if (strlen(dateString) < kDateTimeStringLength) {
40  return LocalDateTime::forError();
41  }
42  return forDateStringChainable(dateString);
43 }
44 
45 
46 LocalDateTime LocalDateTime::forDateStringChainable(const char*& dateString) {
47  const char* s = dateString;
48 
49  // date
50  LocalDate ld = LocalDate::forDateStringChainable(s);
51 
52  // 'T'
53  s++;
54 
55  // time
56  LocalTime lt = LocalTime::forTimeStringChainable(s);
57 
58  dateString = s;
59  return LocalDateTime(ld, lt);
60 }
61 
62 }
63 
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
Definition: LocalTime.h:20
uint8_t month() const
Return the month with January=1, December=12.
Definition: LocalDate.h:215
bool isError() const
Return true if any component indicates an error condition.
static LocalDateTime forDateString(const char *dateString)
Factory method.
void printTo(Print &printer) const
Print LocalDateTime to &#39;printer&#39; in ISO 8601 format.
int16_t year() const
Return the full year instead of just the last 2 digits.
Definition: LocalDate.h:203
uint8_t day() const
Return the day of the month.
Definition: LocalDate.h:221
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
The date (year, month, day) representing the date without regards to time zone.
Definition: LocalDate.h:32
uint8_t hour() const
Return the hour.
Definition: LocalTime.h:99
uint8_t second() const
Return the second.
Definition: LocalTime.h:111
LocalDateTime()
Constructor.
uint8_t minute() const
Return the minute.
Definition: LocalTime.h:105
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).