getdate.c File Reference

#include <time.h>
#include <locale.h>
#include <stdio.h>
#include "machine.h"
#include "sciprint.h"
#include <sys/time.h>

Include dependency graph for getdate.c:

Go to the source code of this file.

Defines

#define ISO_WEEK_START_WDAY   1
#define ISO_WEEK1_WDAY   4
#define YDAY_MINIMUM   (-366)
#define TM_YEAR_BASE   1900
#define __isleap(year)   ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))

Functions

static int week_number __PARAMS ((struct tm *tp))
void C2F (scigetdate)
void C2F() convertdate (time_t *dt, int w[10])
static int week_days (int yday, int wday)
static int week_number (struct tm *tp)


Define Documentation

#define __isleap ( year   )     ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))

Definition at line 30 of file getdate.c.

Referenced by week_number().

#define ISO_WEEK1_WDAY   4

Definition at line 24 of file getdate.c.

Referenced by week_days().

#define ISO_WEEK_START_WDAY   1

Definition at line 23 of file getdate.c.

Referenced by week_days().

#define TM_YEAR_BASE   1900

Definition at line 26 of file getdate.c.

Referenced by week_number().

#define YDAY_MINIMUM   (-366)

Definition at line 25 of file getdate.c.

Referenced by week_days().


Function Documentation

static int week_number __PARAMS ( (struct tm *tp)   )  [static]

void C2F ( scigetdate   ) 

Definition at line 42 of file getdate.c.

00055 {
00056   *ierr=0;
00057   if (time(dt) == (time_t) - 1) 
00058   {
00059     *ierr=1;
00060   }
00061   ChronoFlag=1;
00062   
00063   #ifdef _MSC_VER
00064     _ftime64( &timebufferW );
00065   #else
00066         gettimeofday(&timebufferU,NULL);
00067   #endif
00068 }

void C2F() convertdate ( time_t *  dt,
int  w[10] 
)

Definition at line 70 of file getdate.c.

References NULL, sciprint(), and week_number().

00071 {
00072         #ifdef _MSC_VER
00073         if ( (*dt<0) || (*dt> _MAX__TIME64_T) )
00074         #else
00075         if (*dt<0)
00076         #endif
00077         {
00078                 w[0] = 0;
00079                 w[1] = 0;
00080                 w[2] = 0;
00081                 w[3] = 0;
00082                 w[4] = 0;
00083                 w[5] = 0;
00084                 w[6] = 0;
00085                 w[7] = 0;
00086                 w[8] = 0;
00087                 w[9] = 0;
00088                 if (*dt<0)      sciprint("dt=getdate(x) x must be > 0.\n");
00089                 #ifdef _MSC_VER
00090                 else sciprint("dt=getdate(x) x must be < %d.\n",_MAX__TIME64_T);
00091                 #endif
00092         }
00093         else
00094         {
00095                 struct tm *nowstruct=NULL;
00096                 nowstruct = localtime(dt);
00097                 if (nowstruct)
00098                 {
00099                         w[0] = 1900 + nowstruct->tm_year;
00100                         w[1] = 1    + nowstruct->tm_mon;
00101                         w[2] = week_number(nowstruct);
00102                         w[3] = 1    + nowstruct->tm_yday;
00103                         w[4] = 1    + nowstruct->tm_wday;
00104                         w[5] =        nowstruct->tm_mday;
00105                         w[6] =        nowstruct->tm_hour;
00106                         w[7] =        nowstruct->tm_min;
00107                         w[8] =        nowstruct->tm_sec;
00108             if (ChronoFlag)
00109                         {
00110        #ifdef _MSC_VER
00111                                 w[9] = timebufferW.millitm;
00112                          #else
00113                                 w[9] = timebufferU.tv_usec / 1000;  /* micro to ms */
00114                          #endif
00115                          ChronoFlag=0;
00116                         }
00117                         else
00118                         {
00119                                 w[9] = 0;
00120                         }
00121                 }
00122         }
00123 }

Here is the call graph for this function:

static int week_days ( int  yday,
int  wday 
) [static]

Definition at line 131 of file getdate.c.

References ISO_WEEK1_WDAY, ISO_WEEK_START_WDAY, and YDAY_MINIMUM.

Referenced by week_number().

00132 {
00133   /* Add enough to the first operand of % to make it nonnegative.  */
00134   int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
00135   return (yday - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
00136 }

Here is the caller graph for this function:

static int week_number ( struct tm *  tp  )  [static]

Definition at line 147 of file getdate.c.

References __isleap, days, TM_YEAR_BASE, and week_days().

Referenced by convertdate().

00148 {
00149   int year = tp->tm_year + TM_YEAR_BASE;
00150   int days = week_days (tp->tm_yday, tp->tm_wday);
00151 
00152   if (days < 0)
00153     {
00154       /* This ISO week belongs to the previous year.  */
00155       year--;
00156       days = week_days (tp->tm_yday + (365 + __isleap
00157                                            (year)),
00158                             tp->tm_wday);
00159     }
00160   else
00161     {
00162       int d = week_days (tp->tm_yday - (365 + __isleap
00163                                             (year)),
00164                              tp->tm_wday);
00165       if (0 <= d)
00166         {
00167           /* This ISO week belongs to the next year.  */
00168           year++;
00169           days = d;
00170         }
00171     }
00172   return ( (int)days / 7 + 1);
00173 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Mar 4 16:13:58 2007 for Scilab [trunk] by  doxygen 1.5.1