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::operator_ {
15 
16 STANDARD_OPERATOR_2(time, Equal, type::Bool(), type::Time(), type::Time(), "Compares two time values.")
17 STANDARD_OPERATOR_2(time, Unequal, type::Bool(), type::Time(), type::Time(), "Compares two time values.")
18 STANDARD_OPERATOR_2x(time, SumInterval, Sum, type::Time(), type::Time(), type::Interval(),
19  "Adds the interval to the time.");
20 STANDARD_OPERATOR_2x(time, DifferenceTime, Difference, type::Interval(), type::Time(), type::Time(),
21  "Returns the difference of the times.");
22 STANDARD_OPERATOR_2x(time, DifferenceInterval, Difference, type::Time(), type::Time(), type::Interval(),
23  "Subtracts the interval from the time.");
24 STANDARD_OPERATOR_2(time, Greater, type::Bool(), type::Time(), type::Time(), "Compares the times.");
25 STANDARD_OPERATOR_2(time, GreaterEqual, type::Bool(), type::Time(), type::Time(), "Compares the times.");
26 STANDARD_OPERATOR_2(time, Lower, type::Bool(), type::Time(), type::Time(), "Compares the times.");
27 STANDARD_OPERATOR_2(time, LowerEqual, type::Bool(), type::Time(), type::Time(), "Compares the times.");
28 
29 BEGIN_METHOD(time, Seconds)
30  const auto& signature() const {
31  static auto _signature =
32  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  return _signature;
36  }
37 END_METHOD
38 
39 BEGIN_METHOD(time, Nanoseconds)
40  const auto& signature() const {
41  static auto _signature = Signature{.self = type::Time(),
42  .result = type::UnsignedInteger(64),
43  .id = "nanoseconds",
44  .args = {},
45  .doc = R"(
46 Returns the time as an integer value representing nanoseconds since the UNIX epoch.
47 )"};
48  return _signature;
49  }
50 END_METHOD
51 
52 } // namespace hilti::operator_
Definition: operator-registry.h:15