Skip to content

Commit bf43dba

Browse files
committed
Add @(require_results) to core:time
1 parent 0b4884a commit bf43dba

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

core/time/iso8601.odin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ is specified in the string, that timezone is applied to time.
2727
- Only 4-digit years are accepted.
2828
- Leap seconds are smeared into 23:59:59.
2929
*/
30+
@(require_results)
3031
iso8601_to_time_utc :: proc(iso_datetime: string, is_leap: ^bool = nil) -> (res: Time, consumed: int) {
3132
offset: int
3233
res, offset, consumed = iso8601_to_time_and_offset(iso_datetime, is_leap)
@@ -59,6 +60,7 @@ minutes.
5960
- Only 4-digit years are accepted.
6061
- Leap seconds are smeared into 23:59:59.
6162
*/
63+
@(require_results)
6264
iso8601_to_time_and_offset :: proc(iso_datetime: string, is_leap: ^bool = nil) -> (res: Time, utc_offset: int, consumed: int) {
6365
moment, offset, leap_second, count := iso8601_to_components(iso_datetime)
6466
if count == 0 {
@@ -102,6 +104,7 @@ minutes.
102104
e.g. it'll return hour = 25 if that's what it's given in the specified
103105
string.
104106
*/
107+
@(require_results)
105108
iso8601_to_components :: proc(iso_datetime: string) -> (res: dt.DateTime, utc_offset: int, is_leap: bool, consumed: int) {
106109
moment, offset, count, leap_second, ok := _iso8601_to_components(iso_datetime)
107110
if !ok {

core/time/perf.odin

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ Tick :: struct {
1313
/*
1414
Obtain the current tick.
1515
*/
16+
@(require_results)
1617
tick_now :: proc "contextless" () -> Tick {
1718
return _tick_now()
1819
}
1920

2021
/*
2122
Add duration to a tick.
2223
*/
24+
@(require_results)
2325
tick_add :: proc "contextless" (t: Tick, d: Duration) -> Tick {
2426
return Tick{t._nsec + i64(d)}
2527
}
2628

2729
/*
2830
Obtain the difference between ticks.
2931
*/
32+
@(require_results)
3033
tick_diff :: proc "contextless" (start, end: Tick) -> Duration {
3134
d := end._nsec - start._nsec
3235
return Duration(d)
@@ -43,6 +46,7 @@ then the returned duration is 0.
4346
This procedure is meant to be used in a loop, or in other scenarios, where one
4447
might want to obtain time between multiple ticks at specific points.
4548
*/
49+
@(require_results)
4650
tick_lap_time :: proc "contextless" (prev: ^Tick) -> Duration {
4751
d: Duration
4852
t := tick_now()
@@ -56,6 +60,7 @@ tick_lap_time :: proc "contextless" (prev: ^Tick) -> Duration {
5660
/*
5761
Obtain the duration since last tick.
5862
*/
63+
@(require_results)
5964
tick_since :: proc "contextless" (start: Tick) -> Duration {
6065
return tick_diff(start, tick_now())
6166
}
@@ -101,6 +106,7 @@ This procedure checks if the CPU contains an invariant TSC (Time stamp counter).
101106
Invariant TSC is a feature of modern processors that allows them to run their
102107
TSC at a fixed frequency, independent of ACPI state, and CPU frequency.
103108
*/
109+
@(require_results)
104110
has_invariant_tsc :: proc "contextless" () -> bool {
105111
when ODIN_ARCH == .amd64 {
106112
return x86_has_invariant_tsc()
@@ -122,6 +128,7 @@ dividing the readings from TSC by the duration of the sleep.
122128
123129
The duration of sleep can be controlled by `fallback_sleep` parameter.
124130
*/
131+
@(require_results)
125132
tsc_frequency :: proc "contextless" (fallback_sleep := 2 * Second) -> (u64, bool) {
126133
if !has_invariant_tsc() {
127134
return 0, false

core/time/rfc3339.odin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ offset applied to it.
3131
- Only 4-digit years are accepted.
3232
- Leap seconds are smeared into 23:59:59.
3333
*/
34+
@(require_results)
3435
rfc3339_to_time_utc :: proc(rfc_datetime: string, is_leap: ^bool = nil) -> (res: Time, consumed: int) {
3536
offset: int
3637

@@ -67,6 +68,7 @@ by the RFC 3339 string.
6768
- Only 4-digit years are accepted.
6869
- Leap seconds are smeared into 23:59:59.
6970
*/
71+
@(require_results)
7072
rfc3339_to_time_and_offset :: proc(rfc_datetime: string, is_leap: ^bool = nil) -> (res: Time, utc_offset: int, consumed: int) {
7173
moment, offset, leap_second, count := rfc3339_to_components(rfc_datetime)
7274
if count == 0 {
@@ -109,6 +111,7 @@ represented by the RFC 3339 string.
109111
110112
Performs no validation on whether components are valid, e.g. it'll return hour = 25 if that's what it's given
111113
*/
114+
@(require_results)
112115
rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_offset: int, is_leap: bool, consumed: int) {
113116
moment, offset, count, leap_second, ok := _rfc3339_to_components(rfc_datetime)
114117
if !ok {
@@ -198,6 +201,7 @@ The boolean `ok` is false if the `time` is not a valid datetime, or if allocatin
198201
- `utc_offset`: offset in minutes wrt UTC (ie. the timezone)
199202
- `include_nanos`: whether to include nanoseconds in the result.
200203
*/
204+
@(require_results)
201205
time_to_rfc3339 :: proc(time: Time, utc_offset : int = 0, include_nanos := true, allocator := context.allocator) -> (res: string, ok: bool) {
202206
utc_offset := utc_offset
203207

0 commit comments

Comments
 (0)