Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_time.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * afw_function_execute_* functions for Time
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 /*
19  * Adaptive function: in_range<time>
20  *
21  * afw_function_execute_in_range_time
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Checks if time is between startTime and endTime, inclusive. Regardless of
26  * endTime value, it is always considered to be equal to, but less than 24
27  * hours greater than startTime. If no time zone is specified for time, the
28  * default time zone is used. If no time zone is specified for startTime or
29  * endTime, the time zone of time is used.
30  *
31  * This function is pure, so it will always return the same result
32  * given exactly the same parameters and has no side effects.
33  *
34  * Declaration:
35  *
36  * ```
37  * function in_range<time>(
38  * time: time,
39  * startTime: time,
40  * endTime: time
41  * ): boolean;
42  * ```
43  *
44  * Parameters:
45  *
46  * time - (time)
47  *
48  * startTime - (time)
49  *
50  * endTime - (time)
51  *
52  * Returns:
53  *
54  * (boolean)
55  */
56 const afw_value_t *
59 {
60  afw_xctx_t *xctx = x->xctx;
61  const afw_value_time_t *arg1;
62  const afw_value_time_t *arg2;
63  const afw_value_time_t *arg3;
64  afw_time_t time1, time2, time3;
65  afw_integer_t usec1, usec2, usec3;
66 
70 
71  /* Make working copy of times. */
72  memcpy(&time1, &arg1->internal, sizeof(time1));
73  memcpy(&time2, &arg2->internal, sizeof(time2));
74  memcpy(&time3, &arg3->internal, sizeof(time3));
75 
76  /* If there is no arg1 time zone, use scopes local time zone. */
77  if (time1.time_zone.minutes == -1) {
78  time1.time_zone.hours =
79  xctx->local_dateTime_when_created.time_zone.hours;
80  time1.time_zone.minutes =
81  xctx->local_dateTime_when_created.time_zone.minutes;
82  }
83 
84  /* If there is no arg2 time zone, use arg1's time zone. */
85  if (time2.time_zone.minutes == -1) {
86  memcpy(&time2.time_zone, &time1.time_zone, sizeof(time2.time_zone));
87  }
88 
89  /* If there is no arg3 time zone, use arg1's time zone. */
90  if (time3.time_zone.minutes == -1) {
91  memcpy(&time3.time_zone, &time1.time_zone, sizeof(time3.time_zone));
92  }
93 
94  /* Convert times to microseconds for compare. */
95  usec1 = afw_time_to_microseconds_utc(&time1, xctx);
96  usec2 = afw_time_to_microseconds_utc(&time2, xctx);
97  usec3 = afw_time_to_microseconds_utc(&time3, xctx);
98 
99  /* If usec1 < usec2, add one day to usec1. */
100  if (usec1 < usec2) {
101  usec1 += AFW_TIME_DAYS_TO_MICROSECONDS(1);
102  }
103 
104  /* If usec3 < usec2, add one day to usec3. */
105  if (usec3 < usec2) {
106  usec3 += AFW_TIME_DAYS_TO_MICROSECONDS(1);
107  }
108 
109  /* Return boolean result of in range test. */
110  return (usec1 >= usec2 && usec1 <= usec3)
112 
117 }
Adaptive Framework Core Internal.
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
#define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
Definition: afw_function.h:328
const afw_value_t * afw_function_execute_in_range_time(afw_function_execute_t *x)
Adaptive Function in_range<time>
afw_time_to_microseconds_utc(const afw_time_t *time, afw_xctx_t *xctx)
Convert time normalize to utc to microseconds.
Definition: afw_time.c:665
afw_value_false
Adaptive value false.
Definition: afw_value.h:354
afw_value_true
Adaptive value true.
Definition: afw_value.h:348
afw_time_zone_t time_zone
Definition: afw_common.h:1769
Function execute parameter.
Definition: afw_function.h:53
afw_xctx_t * xctx
The execution context (xctx) of caller.
Definition: afw_function.h:62
time with time zone.
Definition: afw_common.h:1746
afw_time_zone_t time_zone
Definition: afw_common.h:1752
afw_int8_t minutes
Definition: afw_common.h:1688
afw_int8_t hours
Definition: afw_common.h:1682
Interface afw_value public struct.
struct for data type time values.
Interface afw_xctx public struct.