summaryrefslogtreecommitdiffstats
path: root/raddb/mods-available/date
blob: 2d7d85ed99f64828b5d8cbfaa4fa88aebce96790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
#  Registers xlat to convert between time formats.
#
#  xlat input string is an attribute name. If this attribute is of date
#  or integer type, the date xlat will convert it to a time string in
#  the format of the format config item.
#
#  If the attribute is a string type, date will attempt to parse it in
#  the format specified by the format config item, and will expand
#  to a Unix timestamp.
#
date {
	format = "%b %e %Y %H:%M:%S %Z"

	# Use UTC instead of local time.
	#
	#  default = no
#	utc = yes
}

#
#  The WISPr-Session-Terminate-Time attribute is of type "string",
#  and not "date".  Use this expansion to create an attribute
#  that holds an actual date:
#
#	Tmp-Date-0 := "%{wispr2date:&reply:WISPr-Session-Terminate-Time}"
#
date wispr2date {
	format = "%Y-%m-%dT%H:%M:%S"

	# Use UTC instead of local time.
	#
	#  default = no
#	utc = yes
}

#
#  The date module also provides the %{time_since:} xlat, which
#  makes it possible to both:
#    - get the time since the epoch in seconds, milliseconds or
#      microseconds; and
#    - calculate the time elapsed since a given time.
#
#  Syntax is: %{time_since:BASE[ (number|&attribute)]}
#  where "BASE" is "s", "ms" or "us".
#
#  Examples:
#    %{time_since:s}
#        - time in seconds since the epoch, same as %c
#
#    %{time_since:s 1695753388}
#        - time in seconds since Tue 26 Sep 19:36:28 BST 2023
#          (which is 1695753388 in UNIX time)
#
#    %{time_since:s &Tmp-Integer-0}
#        - Time since the number of seconds in Tmp-Integer-0
#
#    %{time_since:ms}
#        - Milliseconds since the epoch
#
#    %{time_since:us}
#        - Microseconds since the epoch
#
#  The provided attribute should be an Integer (or Integer64 for
#  ms or us bases). However, other attributes will be converted if
#  possible, with a warning given. The only one that might make
#  sense is a Date attribute (which will be scaled appropriately
#  according to the base, as Date is always in seconds).
#
#  Primary usage would be for taking latenct measurements, for
#  example to calculate the number of microseconds an LDAP call
#  took:
#
#    update request {
#      &Tmp-Integer64-0 := %{time_since:us}"
#    }
#    ldap
#    update request {
#      &Tmp-Integer64-1 := %{time_since:us &Tmp-Integer64-0}"
#    }