Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/platform/mbed_mktime.h@3:6fe17b8a6d62, 2021-03-09 (annotated)
- Committer:
- boro
- Date:
- Tue Mar 09 13:10:40 2021 +0000
- Revision:
- 3:6fe17b8a6d62
- Parent:
- 0:4beb2ea291ec
SDBlockDevice added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 0:4beb2ea291ec | 1 | |
boro | 0:4beb2ea291ec | 2 | /** \addtogroup platform */ |
boro | 0:4beb2ea291ec | 3 | /** @{*/ |
boro | 0:4beb2ea291ec | 4 | /* mbed Microcontroller Library |
boro | 0:4beb2ea291ec | 5 | * Copyright (c) 2017-2017 ARM Limited |
boro | 0:4beb2ea291ec | 6 | * |
boro | 0:4beb2ea291ec | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
boro | 0:4beb2ea291ec | 8 | * you may not use this file except in compliance with the License. |
boro | 0:4beb2ea291ec | 9 | * You may obtain a copy of the License at |
boro | 0:4beb2ea291ec | 10 | * |
boro | 0:4beb2ea291ec | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
boro | 0:4beb2ea291ec | 12 | * |
boro | 0:4beb2ea291ec | 13 | * Unless required by applicable law or agreed to in writing, software |
boro | 0:4beb2ea291ec | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
boro | 0:4beb2ea291ec | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
boro | 0:4beb2ea291ec | 16 | * See the License for the specific language governing permissions and |
boro | 0:4beb2ea291ec | 17 | * limitations under the License. |
boro | 0:4beb2ea291ec | 18 | */ |
boro | 0:4beb2ea291ec | 19 | |
boro | 0:4beb2ea291ec | 20 | #ifndef MBED_MKTIME_H |
boro | 0:4beb2ea291ec | 21 | #define MBED_MKTIME_H |
boro | 0:4beb2ea291ec | 22 | |
boro | 0:4beb2ea291ec | 23 | #include <time.h> |
boro | 0:4beb2ea291ec | 24 | #include <stdbool.h> |
boro | 0:4beb2ea291ec | 25 | #include <stdint.h> |
boro | 0:4beb2ea291ec | 26 | |
boro | 0:4beb2ea291ec | 27 | #ifdef __cplusplus |
boro | 0:4beb2ea291ec | 28 | extern "C" { |
boro | 0:4beb2ea291ec | 29 | #endif |
boro | 0:4beb2ea291ec | 30 | |
boro | 0:4beb2ea291ec | 31 | /** |
boro | 0:4beb2ea291ec | 32 | * \defgroup platform_mktime mktime functions |
boro | 0:4beb2ea291ec | 33 | * @{ |
boro | 0:4beb2ea291ec | 34 | */ |
boro | 0:4beb2ea291ec | 35 | |
boro | 0:4beb2ea291ec | 36 | /** Compute if a year is a leap year or not. |
boro | 0:4beb2ea291ec | 37 | * |
boro | 0:4beb2ea291ec | 38 | * @param year The year to test it shall be in the range [70:138]. Year 0 is |
boro | 0:4beb2ea291ec | 39 | * translated into year 1900 CE. |
boro | 0:4beb2ea291ec | 40 | * @return true if the year in input is a leap year and false otherwise. |
boro | 0:4beb2ea291ec | 41 | * @note - For use by the HAL only |
boro | 0:4beb2ea291ec | 42 | */ |
boro | 0:4beb2ea291ec | 43 | bool _rtc_is_leap_year(int year); |
boro | 0:4beb2ea291ec | 44 | |
boro | 0:4beb2ea291ec | 45 | /* Convert a calendar time into time since UNIX epoch as a time_t. |
boro | 0:4beb2ea291ec | 46 | * |
boro | 0:4beb2ea291ec | 47 | * This function is a thread safe (partial) replacement for mktime. It is |
boro | 0:4beb2ea291ec | 48 | * tailored around RTC peripherals needs and is not by any mean a complete |
boro | 0:4beb2ea291ec | 49 | * replacement of mktime. |
boro | 0:4beb2ea291ec | 50 | * |
boro | 0:4beb2ea291ec | 51 | * @param calendar_time The calendar time to convert into a time_t since epoch. |
boro | 0:4beb2ea291ec | 52 | * The fields from tm used for the computation are: |
boro | 0:4beb2ea291ec | 53 | * - tm_sec |
boro | 0:4beb2ea291ec | 54 | * - tm_min |
boro | 0:4beb2ea291ec | 55 | * - tm_hour |
boro | 0:4beb2ea291ec | 56 | * - tm_mday |
boro | 0:4beb2ea291ec | 57 | * - tm_mon |
boro | 0:4beb2ea291ec | 58 | * - tm_year |
boro | 0:4beb2ea291ec | 59 | * Other fields are ignored and won't be renormalized by a call to this function. |
boro | 0:4beb2ea291ec | 60 | * A valid calendar time is comprised between the 1st january of 1970 at |
boro | 0:4beb2ea291ec | 61 | * 00:00:00 and the 19th of january 2038 at 03:14:07. |
boro | 0:4beb2ea291ec | 62 | * |
boro | 0:4beb2ea291ec | 63 | * @return The calendar time as seconds since UNIX epoch if the input is in the |
boro | 0:4beb2ea291ec | 64 | * valid range. Otherwise ((time_t) -1). |
boro | 0:4beb2ea291ec | 65 | * |
boro | 0:4beb2ea291ec | 66 | * @note Leap seconds are not supported. |
boro | 0:4beb2ea291ec | 67 | * @note Values in output range from 0 to INT_MAX. |
boro | 0:4beb2ea291ec | 68 | * @note - For use by the HAL only |
boro | 0:4beb2ea291ec | 69 | */ |
boro | 0:4beb2ea291ec | 70 | time_t _rtc_mktime(const struct tm* calendar_time); |
boro | 0:4beb2ea291ec | 71 | |
boro | 0:4beb2ea291ec | 72 | /* Convert a given time in seconds since epoch into calendar time. |
boro | 0:4beb2ea291ec | 73 | * |
boro | 0:4beb2ea291ec | 74 | * This function is a thread safe (partial) replacement for localtime. It is |
boro | 0:4beb2ea291ec | 75 | * tailored around RTC peripherals specification and is not by any means a |
boro | 0:4beb2ea291ec | 76 | * complete of localtime. |
boro | 0:4beb2ea291ec | 77 | * |
boro | 0:4beb2ea291ec | 78 | * @param timestamp The time (in seconds) to convert into calendar time. Valid |
boro | 0:4beb2ea291ec | 79 | * input are in the range [0 : INT32_MAX]. |
boro | 0:4beb2ea291ec | 80 | * @param calendar_time Pointer to the object which will contain the result of |
boro | 0:4beb2ea291ec | 81 | * the conversion. The tm fields filled by this function are: |
boro | 0:4beb2ea291ec | 82 | * - tm_sec |
boro | 0:4beb2ea291ec | 83 | * - tm_min |
boro | 0:4beb2ea291ec | 84 | * - tm_hour |
boro | 0:4beb2ea291ec | 85 | * - tm_mday |
boro | 0:4beb2ea291ec | 86 | * - tm_mon |
boro | 0:4beb2ea291ec | 87 | * - tm_year |
boro | 0:4beb2ea291ec | 88 | * - tm_wday |
boro | 0:4beb2ea291ec | 89 | * - tm_yday |
boro | 0:4beb2ea291ec | 90 | * The object remains untouched if the time in input is invalid. |
boro | 0:4beb2ea291ec | 91 | * @return true if the conversion was successful, false otherwise. |
boro | 0:4beb2ea291ec | 92 | * |
boro | 0:4beb2ea291ec | 93 | * @note - For use by the HAL only |
boro | 0:4beb2ea291ec | 94 | */ |
boro | 0:4beb2ea291ec | 95 | bool _rtc_localtime(time_t timestamp, struct tm* calendar_time); |
boro | 0:4beb2ea291ec | 96 | |
boro | 0:4beb2ea291ec | 97 | /** @}*/ |
boro | 0:4beb2ea291ec | 98 | |
boro | 0:4beb2ea291ec | 99 | #ifdef __cplusplus |
boro | 0:4beb2ea291ec | 100 | } |
boro | 0:4beb2ea291ec | 101 | #endif |
boro | 0:4beb2ea291ec | 102 | |
boro | 0:4beb2ea291ec | 103 | #endif /* MBED_MKTIME_H */ |
boro | 0:4beb2ea291ec | 104 | |
boro | 0:4beb2ea291ec | 105 | /** @}*/ |