aboutsummaryrefslogtreecommitdiff
path: root/tests/core/test_gmtime.in
blob: 7b7227ba409ad1666c794c3c4d773eed907b403b (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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

int main(void) {
  time_t t = time(NULL);
  struct tm *ptm = gmtime(&t);
  struct tm tmCurrent = *ptm;
  int hour = tmCurrent.tm_hour;

  t -= hour * 3600;  // back to midnight
  int yday = -1;
  for (hour = 0; hour < 24; hour++) {
    ptm = gmtime(&t);
    // tm_yday must be constant all day...
    printf("yday: %d, hour: %d\n", ptm->tm_yday, hour);
    if (yday == -1)
      yday = ptm->tm_yday;
    else
      assert(yday == ptm->tm_yday);
    t += 3600;  // add one hour
  }
  printf("ok!\n");
  return (0);
}