FD.io VPP  v18.07-rc0-415-g6c78436
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 */
32  /*
33  * time in f64 seconds since Thursday 1 Jan 1970 00:00:00 UTC
34  * when clib_time_init was called
35  */
39  clib_timebase_daylight_time_t daylight_time_type;
45 
46 typedef struct
47 {
48  u32 year, month, day, hour, minute, second, nanosecond;
49  /* 0 => Thursday */
53 
54 typedef struct
55 {
56  f64 start, end;
58 
59 void clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
60  clib_timebase_daylight_time_t daylight_type);
61 
64 
66 
70 
73 
75 
77  (clib_timebase_t * tb, f64 now)
78 {
79  if (PREDICT_TRUE
80  (now >= tb->cached_year_start && now <= tb->cached_year_end))
81  {
82  if (now >= tb->cached_summer_start && now <= tb->cached_summer_end)
83  return tb->summer_offset;
84  else
85  return 0.0;
86  }
87  else
88  return clib_timebase_summer_offset (tb, now);
89 }
90 
91 static inline f64
93 {
94  f64 now;
95 
96  now = tb->time_zero + clib_time_now (&tb->clib_time);
97  now += tb->timezone_offset;
98  now += clib_timebase_summer_offset_fastpath (tb, now);
99 
100  return now;
101 }
102 
103 static inline int
105 {
106  int rv;
107 
108  if (PREDICT_TRUE ((year % 4) != 0))
109  return 0;
110 
111  rv = 0;
112 
113  if ((year % 4) == 0)
114  rv = 1;
115  if ((year % 100) == 0)
116  rv = 0;
117  if ((year % 400) == 0)
118  rv = 1;
119  return rv;
120 }
121 
122 #endif /* included_time_range_h */
123 
124 
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
unformat_function_t unformat_clib_timebase_range_hms
Definition: time_range.h:71
#define PREDICT_TRUE(x)
Definition: clib.h:106
static f64 clib_time_now(clib_time_t *c)
Definition: time.h:203
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
clib_timebase_daylight_time_t
Definition: time_range.h:22
static f64 clib_timebase_now(clib_timebase_t *tb)
Definition: time_range.h:92
unsigned int u32
Definition: types.h:88
f64 clib_timebase_offset_from_sunday(u8 *day)
Definition: time_range.c:238
format_function_t format_clib_timebase_time
Definition: time_range.h:74
clib_timebase_daylight_time_t daylight_time_type
Definition: time_range.h:39
f64 clib_timebase_components_to_time(clib_timebase_component_t *cp)
Definition: time_range.c:177
f64 clib_timebase_summer_offset(clib_timebase_t *tb, f64 now)
Definition: time_range.c:383
static f64 clib_timebase_summer_offset_fastpath(clib_timebase_t *tb, f64 now)
Definition: time_range.h:77
void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type)
Definition: time_range.c:19
void clib_timebase_time_to_components(f64 now, clib_timebase_component_t *cp)
Definition: time_range.c:96
f64 clib_timebase_find_sunday_midnight(f64 start_time)
Definition: time_range.c:213
signed int i32
Definition: types.h:81
f64 cached_year_start
Definition: time_range.h:40
f64 cached_summer_end
Definition: time_range.h:43
static int clib_timebase_is_leap_year(u32 year)
Definition: time_range.h:104
f64 cached_summer_start
Definition: time_range.h:42
clib_time_t clib_time
Definition: time_range.h:31
unformat_function_t unformat_clib_timebase_range_vector
Definition: time_range.h:72