This library takes the current time (which must be set to UTC, e.g. via an NTP call), and applies a timezone definition (loaded at startup) to calculate the local time. This includes the handling of daylight saving. See http://mbed.org/users/hlipka/notebook/time-zone-handling/ for more information (esp. how to get a time zone definition file).
Dependents: CubiScan 000-FIN_youcef 005_ESSAI_youcef
Diff: Time.h
- Revision:
- 0:ab93db24fcc8
- Child:
- 1:81f7dd124217
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Time.h Wed Dec 22 23:02:21 2010 +0000 @@ -0,0 +1,91 @@ +#ifndef __TIME_H_ +#define __TIME_H_ + +#include <time.h> +#include "stdio.h" +#include "string.h" +#include <list> + +class Time; + +class TimeStamp { + friend class Time; +public: + int getYear() { + return _tm.tm_year+1900; + }; + + int getMonth() { + return _tm.tm_mon; + }; + + int getDay() { + return _tm.tm_mday; + }; + + int getHour() { + return _tm.tm_hour; + }; + + int getMinute() { + return _tm.tm_min; + }; + + int getSecond() { + return _tm.tm_sec; + }; + + int getDayOfWeek() { + int dow=_tm.tm_wday; + dow--; + if (dow==-1) + dow=6; + return dow; + }; + + int getDayOfYear() { + return _tm.tm_yday; + }; + + TimeStamp(time_t unixTime) { + updateTime(unixTime); + }; + + ~TimeStamp() { + }; + bool isSame(TimeStamp* ts); + bool isBefore(TimeStamp* ts); + bool isAfter(TimeStamp* ts); +private: + void updateTime(time_t unixTime) { + struct tm *time; + time=localtime(&unixTime); + memcpy(&_tm, time, sizeof(_tm)); + } + TimeStamp(int year, int mon, int day, int hour, int min, int sec) + { + _tm.tm_year=year-1900; + _tm.tm_mon=mon; + _tm.tm_mday=day; + _tm.tm_hour=hour; + _tm.tm_min=min; + _tm.tm_sec=sec; + } + + struct tm _tm; +}; + +class TimeZoneEntry; + +class Time { +public: + Time(); + ~Time(); + TimeStamp* getTime(); + long getUnixTime(); +private: + static std::list<TimeZoneEntry*> *_timeZoneEntries; + void readTimeZones(); +}; + +#endif \ No newline at end of file