FreeBASIC  0.91.0
time_setdate.c
Go to the documentation of this file.
1 #include "../fb.h"
2 #include <sys/time.h>
3 
4 int fb_hSetDate( int y, int m, int d )
5 {
6  const int month_len[12] =
7  {
8  2678400, 2419200, 2678400, 2592000, 2678400, 2592000,
9  2678400, 2678400, 2592000, 2678400, 2592000, 2678400
10  };
11 
12  struct timeval tv;
13  time_t secs;
14  int i;
15 
16  if( y < 1970 )
17  return -1;
18  gettimeofday( &tv, NULL );
19  secs = tv.tv_sec % 86400;
20  tv.tv_sec = 0;
21  for( i = 1970; i < y; i++ ) {
22  tv.tv_sec += 31536000;
23  if( ((i % 4) == 0) || ((i / 400) == 0) )
24  d++;
25  }
26  tv.tv_sec += (m * month_len[m-1]);
27  if( ((y % 4) == 0) || ((y / 400) == 0) )
28  d++;
29  tv.tv_sec += (d * 86400) + secs;
30  if( settimeofday( &tv, NULL ) )
31  return -1;
32 
33  return 0;
34 }