G:/ScriptBasic/source/commands/time.c File Reference

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../command.h"

Go to the source code of this file.

Defines

#define _DAY_SEC   (24L * 60L * 60L)
#define _YEAR_SEC   (365L * _DAY_SEC)
#define _FOUR_YEAR_SEC   (1461L * _DAY_SEC)
#define _BASE_DOW   4
#define _BASE_YEAR   70L
#define _MAX_YEAR   138L
#define _LEAP_YEAR_ADJUST   17L
#define ChkAdd(dest, src1, src2)
#define ChkMul(dest, src1, src2)   ( src1 ? (dest/src1 != src2) : 0 )
#define MONTH_NAME_LEN   9
#define WEEK_DAY_NAME_LEN   9
#define NOCOMMAND(XXX)
#define TIMEFUN(NAME, FIELD)
#define TAKE_ARGUMENT(x)
#define TIMEFUN(XXX, YYY)

Functions

static struct tm * mygmtime (time_t *timp, struct tm *ptb)
static long mygmktime (struct tm *tb)
static long TimeDifference (void)
 if (CONVERT2ZCHAR(vFormatString==NULL)
 if (vTimeValue)
 memcpy (STRINGVALUE(RESULT), pszFormatString, strlen(pszFormatString))
 LONGVALUE (RESULT)
 if (NODE nItem==0)
 if (memory_IsUndef(vTime))
 if (nItem==0)
 if (memory_IsUndef(vTime)||memory_IsUndef(vOffset))
 if (pGmTime->tm_mday > 28 &&pGmTime->tm_mon==1 &&(pGmTime->tm_year%4)) pGmTime->tm_mday = 28
 if (pGmTime->tm_mday==31 &&(pGmTime->tm_mon==3||pGmTime->tm_mon==5||pGmTime->tm_mon==7||pGmTime->tm_mon==8||pGmTime->tm_mon==10)) pGmTime->tm_mday
 if (pGmTime->tm_mday > 29 &&pGmTime->tm_mon==1) pGmTime->tm_mday
 TIMEFUN (ADDSECOND, 1)

Variables

static int _lpdays [] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
static int _days [] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }
static char * MonthName []
static char * WeekDayName []
VARIABLE vFormatString
VARIABLE vTimeValue
time_t lTimeValue
NODE nItem
char * pszFormatString
tm * pGmTime
tm GmTime
char * s
char * r
char szNumberBuffer [5]
int hour
int len
 USE_CALLER_MORTALS
 nItem = PARAMETERLIST
 vFormatString = CONVERT2STRING(_EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
else vTimeValue = NULL
 RESULT = NEWMORTALSTRING(strlen(pszFormatString))
END USE_CALLER_MORTALS
 RESULT = NEWMORTALLONG
END USE_CALLER_MORTALS
 RESULT = NEWMORTALLONG
VARIABLE vTime
long lTime
NODE nItem
tm GmTime
GmTime tm_year = 1970
GmTime tm_mon = 1
GmTime tm_mday = 1
GmTime tm_hour = 0
GmTime tm_min = 0
GmTime tm_sec = 0
GmTime tm_isdst = -1
 USE_CALLER_MORTALS
 nItem = PARAMETERLIST
 vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 lTime = LONGVALUE(vTime)
 RESULT = NEWMORTALLONG
END VARIABLE vTime
long lTime
NODE nItem
 USE_CALLER_MORTALS
 nItem = PARAMETERLIST
 vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 lTime = LONGVALUE(vTime)
 RESULT = NEWMORTALLONG
END VARIABLE vTime
END VARIABLE vOffset
time_t lTime
NODE nItem
tm * pGmTime
tm GmTime
 nItem = PARAMETERLIST
 vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 nItem = CDR(nItem)
 vOffset = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 lTime = LONGVALUE(vTime)
 pGmTime = mygmtime(&lTime,&GmTime)
pGmTime tm_year = LONGVALUE(vOffset)
pGmTime tm_isdst = -1
 RESULT = NEWMORTALLONG
END VARIABLE vTime
END VARIABLE vOffset
time_t lTime
NODE nItem
tm * pGmTime
tm GmTime
 nItem = PARAMETERLIST
 vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 nItem = CDR(nItem)
 vOffset = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 ASSERTOKE
 lTime = LONGVALUE(vTime)
 pGmTime = mygmtime(&lTime,&GmTime)
pGmTime tm_mon = LONGVALUE(vOffset)
pGmTime tm_isdst = -1
 RESULT = NEWMORTALLONG


Define Documentation

#define _BASE_DOW   4
 

Definition at line 37 of file time.c.

#define _BASE_YEAR   70L
 

Definition at line 38 of file time.c.

Referenced by mygmktime().

#define _DAY_SEC   (24L * 60L * 60L)
 

Definition at line 34 of file time.c.

Referenced by mygmtime().

#define _FOUR_YEAR_SEC   (1461L * _DAY_SEC)
 

Definition at line 36 of file time.c.

Referenced by mygmtime().

#define _LEAP_YEAR_ADJUST   17L
 

Definition at line 40 of file time.c.

Referenced by mygmktime().

#define _MAX_YEAR   138L
 

Definition at line 39 of file time.c.

Referenced by mygmktime().

#define _YEAR_SEC   (365L * _DAY_SEC)
 

Definition at line 35 of file time.c.

Referenced by mygmtime().

#define ChkAdd dest,
src1,
src2   ) 
 

Value:

( ((src1 >= 0L) && (src2 >= 0L) \
    && (dest < 0L)) || ((src1 < 0L) && (src2 < 0L) && (dest >= 0L)) )

Definition at line 46 of file time.c.

Referenced by mygmktime().

#define ChkMul dest,
src1,
src2   )     ( src1 ? (dest/src1 != src2) : 0 )
 

Definition at line 52 of file time.c.

Referenced by mygmktime().

#define MONTH_NAME_LEN   9
 

Definition at line 253 of file time.c.

#define NOCOMMAND XXX   ) 
 

Value:

COMMAND(XXX)\
NOTIMPLEMENTED;\
END

Definition at line 606 of file time.c.

#define TAKE_ARGUMENT  ) 
 

Value:

vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)));\
  ASSERTOKE;\
  if( vTime )GmTime.x = LONGVALUE(vTime);\
  nItem = CDR(nItem);\
  if( nItem == 0 )goto NoMoreTime;\

Referenced by if().

#define TIMEFUN XXX,
YYY   ) 
 

Value:

COMMAND(XXX)\
  VARIABLE vTime,vOffset;\
  long lTime;\
  NODE nItem;\
\
  nItem = PARAMETERLIST;\
  if( nItem == 0 ){\
    RESULT = NULL;\
    RETURN;\
    }\
  vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)));\
  ASSERTOKE;\
  nItem = CDR(nItem);\
  vOffset = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)));\
  ASSERTOKE;\
  if( memory_IsUndef(vTime) || memory_IsUndef(vOffset) ){\
    RESULT = NULL;\
    RETURN;\
    }\
  lTime = LONGVALUE(vTime);\
  RESULT = NEWMORTALLONG;\
  ASSERTNULL(RESULT)\
  LONGVALUE(RESULT) = lTime + LONGVALUE(vOffset)*YYY;\
END

Definition at line 999 of file time.c.

#define TIMEFUN NAME,
FIELD   ) 
 

Value:

COMMAND(NAME)\
\
 VARIABLE vTime;\
 time_t lTime;\
 NODE nItem;\
 struct tm *pGmTime,GmTime;\
\
  USE_CALLER_MORTALS;\
  nItem = PARAMETERLIST;\
  if( nItem ){\
    vTime = EVALUATEEXPRESSION(CAR(nItem));\
    ASSERTOKE;\
  }else\
    vTime = NULL;\
\
  RESULT = NEWMORTALLONG;\
  ASSERTNULL(RESULT)\
\
  if( memory_IsUndef(vTime) )\
    lTime = (long)time(NULL)+ TimeDifference();\
  else\
    lTime = LONGVALUE(CONVERT2LONG(vTime));\
\
  pGmTime = mygmtime(&lTime,&GmTime);\
  LONGVALUE(RESULT) = pGmTime->FIELD;\
END

Definition at line 999 of file time.c.

#define WEEK_DAY_NAME_LEN   9
 

Definition at line 258 of file time.c.


Function Documentation

if pGmTime->  tm_mday,
29 &&pGmTime->  tm_mon = =1
 

if pGmTime->  tm_mday = =31 &&(pGmTime->tm_mon==3||pGmTime->tm_mon==5||pGmTime->tm_mon==7||pGmTime->tm_mon==8||pGmTime->tm_mon==10)  ) 
 

if pGmTime->  tm_mday,
28 &&pGmTime->  tm_mon = =1 &&(pGmTime->tm_year%4)
= 28
 

if memory_IsUndef(vTime)||memory_IsUndef(vOffset  ) 
 

Definition at line 912 of file time.c.

References RETURN.

if nItem  = = 0  ) 
 

Definition at line 856 of file time.c.

References RETURN.

if memory_IsUndef(vTime  ) 
 

Definition at line 828 of file time.c.

References RETURN.

if NODE  nItem = = 0  ) 
 

Definition at line 778 of file time.c.

References RETURN, and TAKE_ARGUMENT.

if vTimeValue   ) 
 

Definition at line 332 of file time.c.

if CONVERT2ZCHAR(  vFormatString = NULL  ) 
 

Definition at line 322 of file time.c.

LONGVALUE RESULT   ) 
 

memcpy STRINGVALUE(RESULT ,
pszFormatString  ,
strlen(pszFormatString
 

static long mygmktime struct tm *  tb  )  [static]
 

Definition at line 56 of file time.c.

References _BASE_YEAR, _days, _LEAP_YEAR_ADJUST, _MAX_YEAR, ChkAdd, ChkMul, mygmtime(), and NULL.

static struct tm * mygmtime time_t *  timp,
struct tm *  ptb
[static]
 

Definition at line 153 of file time.c.

References _DAY_SEC, _FOUR_YEAR_SEC, _YEAR_SEC, and NULL.

Referenced by log_printf(), log_thread(), mygmktime(), and TimeDifference().

static long TimeDifference void   )  [static]
 

Definition at line 241 of file time.c.

References lTime, mygmtime(), NULL, and pGmTime.

TIMEFUN ADDSECOND  ,
 

ADDSECOND =section time =display AddSecond()

This function takes two arguments. The first argument is a time value, the second is an integer value. The function increments the seconds by the second argument and returns the time value.

This function is the simplest from the arithmetic's point of view, because it simply adds the second argument to the first argument and returns the result.


Variable Documentation

int _days[] = { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 } [static]
 

Definition at line 42 of file time.c.

Referenced by mygmktime().

int _lpdays[] = { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 } [static]
 

Definition at line 41 of file time.c.

ASSERTOKE
 

Definition at line 968 of file time.c.

ASSERTOKE
 

Definition at line 965 of file time.c.

ASSERTOKE
 

Definition at line 911 of file time.c.

ASSERTOKE
 

Definition at line 908 of file time.c.

ASSERTOKE
 

Definition at line 861 of file time.c.

ASSERTOKE
 

Definition at line 827 of file time.c.

ASSERTOKE
 

Definition at line 321 of file time.c.

struct tm GmTime
 

Definition at line 957 of file time.c.

struct tm GmTime
 

Definition at line 900 of file time.c.

struct tm GmTime
 

Definition at line 765 of file time.c.

struct tm GmTime
 

Definition at line 310 of file time.c.

int hour
 

Definition at line 313 of file time.c.

int len
 

Definition at line 313 of file time.c.

Referenced by build_TableItemBytes(), dupl(), mcsub(), p_b_cclass(), p_b_coll_elem(), printDouble(), printInt(), regcomp(), and regerror().

lTime = LONGVALUE(vTime)
 

Definition at line 973 of file time.c.

time_t lTime
 

Definition at line 955 of file time.c.

lTime = LONGVALUE(vTime)
 

Definition at line 916 of file time.c.

time_t lTime
 

Definition at line 898 of file time.c.

lTime = LONGVALUE(vTime)
 

Definition at line 866 of file time.c.

long lTime
 

Definition at line 851 of file time.c.

lTime = LONGVALUE(vTime)
 

Definition at line 832 of file time.c.

long lTime
 

Definition at line 763 of file time.c.

Referenced by file_time_accessed(), file_time_created(), file_time_modified(), and TimeDifference().

time_t lTimeValue
 

Definition at line 307 of file time.c.

char* MonthName[] [static]
 

Initial value:

 {
  "January", "February", "March", "April", "May", "June", 
  "July", "August", "September", "October", "November", "December"
  }

Definition at line 254 of file time.c.

nItem = CDR(nItem)
 

Definition at line 966 of file time.c.

nItem = PARAMETERLIST
 

Definition at line 959 of file time.c.

NODE nItem
 

Definition at line 956 of file time.c.

nItem = CDR(nItem)
 

Definition at line 909 of file time.c.

nItem = PARAMETERLIST
 

Definition at line 902 of file time.c.

NODE nItem
 

Definition at line 899 of file time.c.

nItem = PARAMETERLIST
 

Definition at line 855 of file time.c.

NODE nItem
 

Definition at line 852 of file time.c.

nItem = PARAMETERLIST
 

Definition at line 777 of file time.c.

NODE nItem
 

Definition at line 764 of file time.c.

nItem = PARAMETERLIST
 

Definition at line 318 of file time.c.

NODE nItem
 

Definition at line 308 of file time.c.

pGmTime = mygmtime(&lTime,&GmTime)
 

Definition at line 974 of file time.c.

struct tm* pGmTime
 

Definition at line 957 of file time.c.

pGmTime = mygmtime(&lTime,&GmTime)
 

Definition at line 917 of file time.c.

struct tm* pGmTime
 

Definition at line 900 of file time.c.

struct tm* pGmTime
 

Definition at line 310 of file time.c.

Referenced by TimeDifference().

char* pszFormatString
 

Definition at line 309 of file time.c.

char * r
 

Definition at line 311 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 991 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 925 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 867 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 833 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 600 of file time.c.

RESULT = NEWMORTALLONG
 

Definition at line 581 of file time.c.

RESULT = NEWMORTALSTRING(strlen(pszFormatString))
 

Definition at line 561 of file time.c.

char* s
 

Definition at line 311 of file time.c.

char szNumberBuffer[5]
 

Definition at line 311 of file time.c.

GmTime tm_hour = 0
 

Definition at line 771 of file time.c.

pGmTime tm_isdst = -1
 

Definition at line 990 of file time.c.

pGmTime tm_isdst = -1
 

Definition at line 924 of file time.c.

GmTime tm_isdst = -1
 

Definition at line 774 of file time.c.

GmTime tm_mday = 1
 

Definition at line 770 of file time.c.

GmTime tm_min = 0
 

Definition at line 772 of file time.c.

pGmTime tm_mon = LONGVALUE(vOffset)
 

Definition at line 975 of file time.c.

GmTime tm_mon = 1
 

Definition at line 769 of file time.c.

GmTime tm_sec = 0
 

Definition at line 773 of file time.c.

pGmTime tm_year = LONGVALUE(vOffset)
 

Definition at line 918 of file time.c.

GmTime tm_year = 1970
 

Definition at line 768 of file time.c.

USE_CALLER_MORTALS
 

Definition at line 854 of file time.c.

USE_CALLER_MORTALS
 

Definition at line 776 of file time.c.

END USE_CALLER_MORTALS
 

GMTIME =section time =display GmTime()

This function returns the GMT time expressed as seconds since January 1, 1970, 00:00am. The function does not accept any argument. This function is similar to the function R<NOW> but returns the GMT time instead of the actual local time.

Definition at line 599 of file time.c.

END USE_CALLER_MORTALS
 

NOW =section time =display Now()

This function returns the local time expressed as seconds since January 1, 1970, 00:00am. The function does not accept any argument. This function is similar to the function R<GMTIME> but returns the local time instead of the actual GMT.

Definition at line 580 of file time.c.

USE_CALLER_MORTALS
 

Definition at line 316 of file time.c.

vFormatString = CONVERT2STRING(_EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 320 of file time.c.

VARIABLE vFormatString
 

FORMATDATE =section time =display FORMATDATE()

=verbatim FormatDate("format",time) =noverbatim

Formats a time value (or date) according to the format string. The format string may contain placeholders. The first argument is the format string the second argument is the time value to convert. If the second argument is missing or T<undef> then the local time is converted.

=details This function uses the first argument as a formatting string. This string may contain the following character strings:

=verbatim YEAR four digit year YY two digit year MON three letter abbreviation of the month name MM month 0M month with leading zero if needed MONTH-NAME* name of the month DD day of the month 0D day of the month with leading zero if needed WD week day on a single digit starting with sunday=0 WEEKDAY-NAME the name of the weekday WDN three letter abbreviation fo the week day name HH hours (24 hours notation) 0H hours with leading zero if needed (24 hours notation) hh hours (12 hours notation) 0h hours with leading zero if needed (12 hours notation) mm minutes 0m minutes with leading zero if needed am pm is am or pm =noverbatim

Any other character in the format string will get into the result verbatim.

Definition at line 306 of file time.c.

vOffset = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 967 of file time.c.

END VARIABLE vOffset
 

Definition at line 954 of file time.c.

vOffset = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 910 of file time.c.

END VARIABLE vOffset
 

Definition at line 897 of file time.c.

vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 964 of file time.c.

END VARIABLE vTime
 

ADDMONTH =section time =display AddMonth()

This function takes two arguments. The first argument is a time value, the second is an integer value. The function increments the month by the second argument and returns the time value for the same day, hour and minute but some months later or sooner in case the second argument is negative.

If the resulting value is on a day that does not exist on the result month then the day part of the result is decreased. For example:

=verbatim print FormatTime("MONTH DAY, YEAR",AddMonth(TimeValue(2000,03,31),1)) =noverbatim

will print

=verbatim April 30, 2000 =noverbatim

Definition at line 954 of file time.c.

vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 907 of file time.c.

END VARIABLE vTime
 

ADDYEAR =section time =display AddYear()

This function takes two arguments. The first argument is a time value, the second is an integer value. The function increments the year of the time value by the second argument and returns the time value for the same month, day, hour and minute but some years later or sooner in case the second argument is negative.

This is a bit more complex than just adding 365*24*60*60 to the value, because leap-years are longer and in case you add several years to the time value you should consider adding these longer years extra days. This is calculated correct in this function.

If the original time value is February 29 on a leap-year and the resulting value is in a year, which is not leap year the function will return February 28.

Note that because of this correction using the function in a loop is not the same as using it once. For example:

=verbatim print AddYear(TimeValue(2000,02,29),4),"\n" print AddYear(AddYear(TimeValue(2000,02,29),2),2),"\n" =noverbatim

will print two different values.

Definition at line 897 of file time.c.

vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 860 of file time.c.

END VARIABLE vTime
 

LOCATLTOGMTIME =section time =display LocalToGmTime()

This function accepts one argument that has to be the number of seconds elapsed since January 1, 1970 0:00 am in local time. The function returns the same number of seconds in GMT. In other words the function converts a local time value to GMT time value.

Definition at line 850 of file time.c.

vTime = CONVERT2LONG(EVALUATEEXPRESSION(CAR(nItem)))
 

Definition at line 826 of file time.c.

VARIABLE vTime
 

TIMEVALUE =section time =display TimeValue()

This function gets zero or more, at most six arguments and interprets them as year, month, day, hour, minute and seconds and calculates the number of seconds elapsed since January 1, 1970 till the time specified. If some arguments are missing or T<undef> the default values are the following: =itemize =item year = 1970 =item month = January =item day = 1st =item hours = 0 =item minutes = 0 =item seconds = 0 =noitemize

Definition at line 762 of file time.c.

else vTimeValue = NULL
 

Definition at line 330 of file time.c.

VARIABLE vTimeValue
 

Definition at line 306 of file time.c.

char* WeekDayName[] [static]
 

Initial value:

{
  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  }

Definition at line 259 of file time.c.


Generated on Sun Mar 12 23:56:34 2006 for ScriptBasic by  doxygen 1.4.6-NO