• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __LINUX_TZDST_H__
33 #define __LINUX_TZDST_H__
34 
35 #include "time.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #ifdef __LITEOS__
42 
43 #define SECSPERMIN  60
44 #define MINSPERHOUR 60
45 #define HOURSPERDAY 24
46 #define DAYSPERWEEK 7
47 #define DAYSPERNYEAR    365
48 #define DAYSPERLYEAR    366
49 #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
50 #define SECSPERDAY  ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
51 #define MONSPERYEAR 12
52 
53 #define TM_YEAR_BASE    1900
54 
55 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
56 
57 /**
58  * @ingroup localtime
59  * @brief Set Time Zone.
60  *
61  * @par Description:
62  * This API is used to set the time zone.
63  *
64  * @attention
65  * <ul>
66  * <li>When setting time zones, format is required to be "tzn[+/-]hh[:mm[:ss]][dzn]" .</li>
67  * </ul>
68  *
69  * @param buff The string point to the time zone going to be setting.
70  *
71  * @retval   None
72  */
73 void settimezone(const char *);
74 
75 /**
76  * @ingroup localtime
77  * @brief Disable daylight saving time.
78  *
79  * @par Description:
80  * This API is used to make daylight saving time useless.
81  *
82  * @param None.
83  *
84  * @retval   None
85  */
86 int dst_disable(void);
87 
88 /**
89  * @ingroup localtime
90  * @brief Enable daylight saving time..
91  *
92  * @par Description:
93  * This API is used to configure daylight saving time.
94  *
95  * @attention
96  * <ul>
97  * <li>When config dst, The configuration format has strict requirements.</li>
98  * <li>The first configuration format for example "Feb-03 03:00:00"</li>
99  * <li>The second configuration format for example "Oct-1st-Fri 03:00:00"</li>
100  * <li>The abbreviations for the months are "Jan",  "Feb", "Mar",  "Apr", "May", "Jun", "Jul", "Aug",
101  * "Sep", "Oct", "Nov", and "Dec".</li>
102  * <li>The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat".</li>
103  * <li>The abbreviations for the weeks of the month are "1st", "2nd", "3rd", "4th", "5th"</li>
104  * <li>When it's only four weekdays this month, the effect of "5th" is the same as "Last"</li>
105  * </ul>
106  *
107  * @param dstStartTime   The string point to the DST start going to be setting.
108  * @param dstEndTime     The string point to the DST end going to be setting.
109  * @param forwardSeconds Indicates the number of seconds that time is allocated when entering DST interval.
110  *
111  * @retval   0 Succeed.
112  * @retval  -1 Failed.
113  */
114 int dst_enable(const char *dstStartTime, const char *dstEndTime, int forwardSeconds);
115 
116 /**
117  * @ingroup localtime
118  * @brief Inquire daylight saving time.
119  *
120  * @par Description:
121  * This API is used to inquire daylight saving time.
122  *
123  * @param year      Represents the year to query start from 1900.
124  * @param dstStart  Used to store daylight savings time start time
125  * @param dstEnd    Used to store daylight savings time end time
126  *
127  * @retval   0 Succeed.
128  * @retval  -1 Failed.
129  */
130 int dst_inquire(int year, struct tm *dstStart, struct tm *dstEnd);
131 
132 #endif /* __LITEOS__ */
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* __LINUX_TZDST_H__ */