Spicy
time.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/builder/type.h>
8 #include <hilti/ast/operators/common.h>
9 #include <hilti/ast/types/integer.h>
10 #include <hilti/ast/types/interval.h>
11 #include <hilti/ast/types/real.h>
12 #include <hilti/ast/types/time.h>
13 
14 namespace hilti {
15 namespace operator_ {
16 
17 STANDARD_OPERATOR_2(time, Equal, type::Bool(), type::Time(), type::Time(), "Compares two time values.")
18 STANDARD_OPERATOR_2(time, Unequal, type::Bool(), type::Time(), type::Time(), "Compares two time values.")
19 STANDARD_OPERATOR_2x(time, SumInterval, Sum, type::Time(), type::Time(), type::Interval(),
20  "Adds the interval to the time.");
21 STANDARD_OPERATOR_2x(time, DifferenceTime, Difference, type::Interval(), type::Time(), type::Time(),
22  "Returns the difference of the times.");
23 STANDARD_OPERATOR_2x(time, DifferenceInterval, Difference, type::Time(), type::Time(), type::Interval(),
24  "Subtracts the interval from the time.");
25 STANDARD_OPERATOR_2(time, Greater, type::Bool(), type::Time(), type::Time(), "Compares the times.");
26 STANDARD_OPERATOR_2(time, GreaterEqual, type::Bool(), type::Time(), type::Time(), "Compares the times.");
27 STANDARD_OPERATOR_2(time, Lower, type::Bool(), type::Time(), type::Time(), "Compares the times.");
28 STANDARD_OPERATOR_2(time, LowerEqual, type::Bool(), type::Time(), type::Time(), "Compares the times.");
29 
30 BEGIN_METHOD(time, Seconds)
31  auto signature() const {
32  return Signature{.self = type::Time(), .result = type::Real(), .id = "seconds", .args = {}, .doc = R"(
33 Returns the time as a real value representing seconds since the UNIX epoch.
34 )"};
35  }
36 END_METHOD
37 
38 BEGIN_METHOD(time, Nanoseconds)
39  auto signature() const {
40  return Signature{.self = type::Time(),
41  .result = type::UnsignedInteger(64),
42  .id = "nanoseconds",
43  .args = {},
44  .doc = R"(
45 Returns the time as an integer value representing nanoseconds since the UNIX epoch.
46 )"};
47  }
48 END_METHOD
49 
50 } // namespace operator_
51 } // namespace hilti