AceTime  1.9.0
Date and time classes for Arduino that support timezones from the TZ Database.
LocalDateTime.cpp
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #include <AceCommon.h>
7 #include "common/DateStrings.h"
8 #include "LocalDateTime.h"
9 
10 using ace_common::printPad2To;
11 
12 namespace ace_time {
13 
14 void LocalDateTime::printTo(Print& printer) const {
15  if (isError()) {
16  printer.print(F("<Invalid LocalDateTime>"));
17  return;
18  }
19 
20  // Date
21  printer.print(mLocalDate.year());
22  printer.print('-');
23  printPad2To(printer, mLocalDate.month(), '0');
24  printer.print('-');
25  printPad2To(printer, mLocalDate.day(), '0');
26 
27  // 'T' separator
28  printer.print('T');
29 
30  // Time
31  printPad2To(printer, mLocalTime.hour(), '0');
32  printer.print(':');
33  printPad2To(printer, mLocalTime.minute(), '0');
34  printer.print(':');
35  printPad2To(printer, mLocalTime.second(), '0');
36 }
37 
39  if (strlen(dateString) < kDateTimeStringLength) {
40  return LocalDateTime::forError();
41  }
42  return forDateStringChainable(dateString);
43 }
44 
45 
47  const char* s = dateString;
48 
49  // date
51 
52  // 'T'
53  s++;
54 
55  // time
57 
58  dateString = s;
59  return LocalDateTime(ld, lt);
60 }
61 
62 }
63 
ace_time::LocalTime::forTimeStringChainable
static LocalTime forTimeStringChainable(const char *&timeString)
Variant of forTimeString() that updates the pointer to the next unprocessed character.
Definition: LocalTime.cpp:35
ace_time::LocalDate::month
uint8_t month() const
Return the month with January=1, December=12.
Definition: LocalDate.h:251
ace_time::LocalDateTime
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:30
ace_time::LocalDateTime::printTo
void printTo(Print &printer) const
Print LocalDateTime to 'printer' in ISO 8601 format.
Definition: LocalDateTime.cpp:14
ace_time::LocalDateTime::forError
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
Definition: LocalDateTime.h:155
ace_time::LocalDate
The date (year, month, day) representing the date without regards to time zone.
Definition: LocalDate.h:36
ace_time::LocalDate::forDateStringChainable
static LocalDate forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
Definition: LocalDate.cpp:72
ace_time::LocalDateTime::forDateStringChainable
static LocalDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
Definition: LocalDateTime.cpp:46
ace_time::LocalDate::day
uint8_t day() const
Return the day of the month.
Definition: LocalDate.h:257
ace_time::LocalDateTime::isError
bool isError() const
Return true if any component indicates an error condition.
Definition: LocalDateTime.h:163
ace_time::LocalDate::year
int16_t year() const
Return the full year instead of just the last 2 digits.
Definition: LocalDate.h:231
ace_time::LocalDateTime::LocalDateTime
LocalDateTime()
Constructor.
Definition: LocalDateTime.h:160
ace_time::LocalTime::hour
uint8_t hour() const
Return the hour.
Definition: LocalTime.h:116
ace_time::LocalTime::second
uint8_t second() const
Return the second.
Definition: LocalTime.h:128
ace_time::LocalTime::minute
uint8_t minute() const
Return the minute.
Definition: LocalTime.h:122
ace_time::LocalDateTime::forDateString
static LocalDateTime forDateString(const char *dateString)
Factory method.
Definition: LocalDateTime.cpp:38
ace_time::LocalTime
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
Definition: LocalTime.h:26