Patternscan new spatial: Debug print
[pachi.git] / timeinfo.c
blob914f55776b372b3c7f1dcce3ba551a8a40f62bfb
1 #include <assert.h>
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include "timeinfo.h"
9 bool
10 time_parse(struct time_info *ti, char *s)
12 switch (s[0]) {
13 case '_': ti->period = TT_TOTAL; s++; break;
14 default: ti->period = TT_MOVE; break;
16 switch (s[0]) {
17 case '=':
18 ti->dim = TD_GAMES;
19 ti->len.games = atoi(++s);
20 break;
21 default:
22 if (!isdigit(s[0]))
23 return false;
24 ti->dim = TD_WALLTIME;
25 ti->len.walltime.tv_sec = atoi(s);
26 ti->len.walltime.tv_nsec = 0;
27 break;
29 return true;
32 void
33 time_add(struct timespec *when, struct timespec *len)
35 when->tv_sec += len->tv_sec;
36 when->tv_nsec += len->tv_nsec;
37 if (when->tv_nsec > 1000000000)
38 when->tv_sec++, when->tv_nsec -= 1000000000;
41 bool
42 time_passed(struct timespec *when)
44 struct timespec now; clock_gettime(CLOCK_REALTIME, &now);
46 return now.tv_sec > when->tv_sec || (now.tv_sec == when->tv_sec && now.tv_nsec > when->tv_nsec);