1 /**************************************************************************/
4 @author K. Townsend (microBuilder.eu)
6 @brief Generic time and RTC-related helper functions
10 Time and RTC-related helper functions.
14 Software License Agreement (BSD License)
16 Copyright (c) 2012, microBuilder SARL
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21 1. Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26 3. Neither the name of the copyright holders nor the
27 names of its contributors may be used to endorse or promote products
28 derived from this software without specific prior written permission.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
31 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 /**************************************************************************/
44 /**************************************************************************/
46 @brief Converts the supplied date and time to seconds since the
47 epoch (00h00, 1 Jan 1970).
54 // 19 Jan 2012 at 13:42:27 ... DST unnknown (-1)
55 epochTime = rtcToEpochTime(2012, 0, 19, 13, 42, 27, -1);
57 // Should return 1326980547 (number of seconds since epoch)
61 /**************************************************************************/
62 long rtcToEpochTime(int year
, int month
, int mday
, int hour
, int min
, int sec
, int isdst
)
64 // This is purely a convenience function since it uses mktime beneath the hood
68 if (year
> 1900) year
-= 1900;
71 t
.tm_mon
= month
; // Month, 0 - jan
72 t
.tm_mday
= mday
; // Day of the month
76 t
.tm_isdst
= isdst
; // Is DST on? 1 = yes, 0 = no, -1 = unknown
79 // Return seconds since the epoch (00h00, 1 Jan 1970)
83 void rtcFunction(void)
This page took 0.045448 seconds and 5 git commands to generate.