FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
time_range.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef included_time_range_h
17 #define included_time_range_h
18 
19 #include <vppinfra/format.h>
20 #include <vppinfra/time.h>
21 
22 typedef enum
23 {
27 
28 typedef struct
29 {
30  /* provides f64 seconds since clib_time_init was called */
40 
41 typedef struct
42 {
43  u32 year, month, day, hour, minute, second, nanosecond;
44  /* 0 => Thursday */
48 
49 typedef struct
50 {
53 
54 void clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
55  clib_timebase_daylight_time_t daylight_type,
56  clib_time_t * clib_time);
57 
60 
62 
66 
69 
71 
74 {
75  if (PREDICT_TRUE
76  (now >= tb->cached_year_start && now <= tb->cached_year_end))
77  {
78  if (now >= tb->cached_summer_start && now <= tb->cached_summer_end)
79  return tb->summer_offset;
80  else
81  return 0.0;
82  }
83  else
84  return clib_timebase_summer_offset (tb, now);
85 }
86 
87 static inline f64
89 {
90  f64 now;
91 
93  now += tb->timezone_offset;
95 
96  return now;
97 }
98 
99 static inline int
101 {
102  int rv;
103 
104  if (PREDICT_TRUE ((year % 4) != 0))
105  return 0;
106 
107  rv = 0;
108 
109  if ((year % 4) == 0)
110  rv = 1;
111  if ((year % 100) == 0)
112  rv = 0;
113  if ((year % 400) == 0)
114  rv = 1;
115  return rv;
116 }
117 
118 #endif /* included_time_range_h */
119 
120 
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "gnu")
126  * End:
127  */
clib_timebase_range_t::start
f64 start
Definition: time_range.h:51
CLIB_TIMEBASE_DAYLIGHT_NONE
@ CLIB_TIMEBASE_DAYLIGHT_NONE
Definition: time_range.h:24
clib_timebase_daylight_time_t
clib_timebase_daylight_time_t
Definition: time_range.h:22
clib_timebase_range_t
Definition: time_range.h:49
i32
signed int i32
Definition: types.h:77
format_clib_timebase_time
format_function_t format_clib_timebase_time
Definition: time_range.h:70
clib_timebase_t::summer_offset
f64 summer_offset
Definition: time_range.h:33
clib_timebase_t
Definition: time_range.h:28
clib_timebase_t::timezone_offset
f64 timezone_offset
Definition: time_range.h:32
end
f64 end
end of the time range
Definition: mactime.api:44
clib_timebase_t::cached_year_end
f64 cached_year_end
Definition: time_range.h:36
clib_timebase_time_to_components
void clib_timebase_time_to_components(f64 now, clib_timebase_component_t *cp)
Definition: time_range.c:104
time.h
clib_timebase_t::cached_year_start
f64 cached_year_start
Definition: time_range.h:35
f64
double f64
Definition: types.h:142
format.h
clib_time_t::init_reference_time
f64 init_reference_time
Definition: time.h:62
clib_time_now
static f64 clib_time_now(clib_time_t *c)
Definition: time.h:230
clib_timebase_component_t::day_name_index
u32 day_name_index
Definition: time_range.h:45
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
clib_timebase_summer_offset_fastpath
static f64 clib_timebase_summer_offset_fastpath(clib_timebase_t *tb, f64 now)
Definition: time_range.h:73
clib_timebase_offset_from_sunday
f64 clib_timebase_offset_from_sunday(u8 *day)
Definition: time_range.c:246
clib_time_t
Definition: time.h:44
u32
unsigned int u32
Definition: types.h:88
clib_timebase_now
static f64 clib_timebase_now(clib_timebase_t *tb)
Definition: time_range.h:88
clib_timebase_t::cached_summer_start
f64 cached_summer_start
Definition: time_range.h:37
clib_timebase_init
void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type, clib_time_t *clib_time)
Definition: time_range.c:19
unformat_function_t
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:225
clib_timebase_components_to_time
f64 clib_timebase_components_to_time(clib_timebase_component_t *cp)
Definition: time_range.c:185
unformat_clib_timebase_range_hms
unformat_function_t unformat_clib_timebase_range_hms
Definition: time_range.h:67
clib_timebase_component_t::fractional_seconds
f64 fractional_seconds
Definition: time_range.h:46
CLIB_TIMEBASE_DAYLIGHT_USA
@ CLIB_TIMEBASE_DAYLIGHT_USA
Definition: time_range.h:25
clib_timebase_summer_offset
f64 clib_timebase_summer_offset(clib_timebase_t *tb, f64 now)
Definition: time_range.c:391
now
f64 now
Definition: nat44_ei_out2in.c:710
clib_timebase_t::daylight_time_type
clib_timebase_daylight_time_t daylight_time_type
Definition: time_range.h:34
clib_timebase_component_t
Definition: time_range.h:41
clib_timebase_t::clib_time
clib_time_t * clib_time
Definition: time_range.h:31
u8
unsigned char u8
Definition: types.h:56
clib_timebase_t::cached_summer_end
f64 cached_summer_end
Definition: time_range.h:38
clib_timebase_find_sunday_midnight
f64 clib_timebase_find_sunday_midnight(f64 start_time)
Definition: time_range.c:221
unformat_clib_timebase_range_vector
unformat_function_t unformat_clib_timebase_range_vector
Definition: time_range.h:68
clib_timebase_is_leap_year
static int clib_timebase_is_leap_year(u32 year)
Definition: time_range.h:100
rv
int __clib_unused rv
Definition: application.c:491
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
clib_timebase_component_t::year
u32 year
Definition: time_range.h:43