forked

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_mktime.h Source File

mbed_mktime.h

00001 
00002 /** \addtogroup platform */
00003 /** @{*/
00004 /* mbed Microcontroller Library
00005  * Copyright (c) 2017-2017 ARM Limited
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  */
00019 
00020 #ifndef MBED_MKTIME_H
00021 #define MBED_MKTIME_H
00022 
00023 #include <time.h>
00024 #include <stdbool.h>
00025 #include <stdint.h>
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 /** Compute if a year is a leap year or not.
00032  *
00033  * @param year The year to test it shall be in the range [70:138]. Year 0 is
00034  * translated into year 1900 CE.
00035  * @return true if the year in input is a leap year and false otherwise.
00036  * @note - For use by the HAL only
00037  */
00038 bool _rtc_is_leap_year(int year);
00039 
00040 /* Convert a calendar time into time since UNIX epoch as a time_t.
00041  *
00042  * This function is a thread safe (partial) replacement for mktime. It is
00043  * tailored around RTC peripherals needs and is not by any mean a complete
00044  * replacement of mktime.
00045  *
00046  * @param calendar_time The calendar time to convert into a time_t since epoch.
00047  * The fields from tm used for the computation are:
00048  *   - tm_sec
00049  *   - tm_min
00050  *   - tm_hour
00051  *   - tm_mday
00052  *   - tm_mon
00053  *   - tm_year
00054  * Other fields are ignored and won't be renormalized by a call to this function.
00055  * A valid calendar time is comprised between the 1st january of 1970 at
00056  * 00:00:00 and the 19th of january 2038 at 03:14:07.
00057  *
00058  * @return The calendar time as seconds since UNIX epoch if the input is in the
00059  * valid range. Otherwise ((time_t) -1).
00060  *
00061  * @note Leap seconds are not supported.
00062  * @note Values in output range from 0 to INT_MAX.
00063  * @note - For use by the HAL only
00064  */
00065 time_t _rtc_mktime(const struct tm* calendar_time);
00066 
00067 /* Convert a given time in seconds since epoch into calendar time.
00068  *
00069  * This function is a thread safe (partial) replacement for localtime. It is
00070  * tailored around RTC peripherals specification and is not by any means a
00071  * complete of localtime.
00072  *
00073  * @param timestamp The time (in seconds) to convert into calendar time. Valid
00074  * input are in the range [0 : INT32_MAX].
00075  * @param calendar_time Pointer to the object which will contain the result of
00076  * the conversion. The tm fields filled by this function are:
00077  *   - tm_sec
00078  *   - tm_min
00079  *   - tm_hour
00080  *   - tm_mday
00081  *   - tm_mon
00082  *   - tm_year
00083  *   - tm_wday
00084  *   - tm_yday
00085  * The object remains untouched if the time in input is invalid.
00086  * @return true if the conversion was successful, false otherwise.
00087  *
00088  * @note - For use by the HAL only
00089  */
00090 bool _rtc_localtime(time_t timestamp, struct tm* calendar_time);
00091 
00092 #ifdef __cplusplus
00093 }
00094 #endif
00095 
00096 #endif /* MBED_MKTIME_H */
00097 
00098 /** @}*/