* harbour/bin/hb-func.sh
! restored default optimization flag (-O3) in hb* scripts
* harbour/harbour.spec
! fixed recent modification
* harbour/contrib/rddads/ads1.c
* harbour/contrib/rddads/adsfunc.c
* harbour/contrib/hbmisc/strfmt.c
* harbour/contrib/hbcrypt/sha1.c
! fixed wrongly used C reference operator
* harbour/contrib/hbwin/win_prn2.c
* harbour/contrib/hbwin/wapi_commctrl.c
* harbour/source/vm/maindllp.c
! fixes for unicode builds
* harbour/include/std.ch
+ added SET TIME FORMAT [TO] <f>
* harbour/include/set.ch
* harbour/include/hbset.h
* harbour/source/vm/set.c
+ added _SET_TIMEFORMAT
The folowing modifiers are supported:
hh - hours
mm - minutes
ss - seconds
fff - fraction part of seconds
p - 1-st letter from PM / AM signature. When used time is shown
in 12 hour format otherwise 24 hour format is used
ex: Set( __SET_TIMEFORMAT, "hh:mm pm" )
default _SET_TIMEFORMAT value is "hh:mm:ss:fff"
+ added C function: char * hb_setGetTimeFormat( void );
* harbour/include/hbpp.h
* harbour/source/pp/ppcore.c
+ added support for timestamp constant values in the form:
t"YYYY-MM-DD HH:MM:SS.fff"
The exact accepted timestamp pattern is is:
YYYY-MM-DD [H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
i.e.:
tValue := t"2009-03-21 5:31:45.437 PM"
or:
YYYY-MM-DDT[H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
with literal "T" as date and time part delimiters (XML timestamp
format), i.e.:
tValue := t"2009-03-21T17:31:45.437"
The folowing characters can be used as date delimiters: "-", "/", "."
if PM or AM is used HH is in range < 1 : 12 > otherwise
in range < 0 : 23 >
* harbour/source/compiler/complex.c
* harbour/source/compiler/harbour.y
* harbour/source/compiler/harbour.yyc
* harbour/source/compiler/harbour.yyh
+ added support for t"YYYY-MM-DD HH:MM:SS.fff" time stamp constant
to compiler
+ added support for VFP datetime constant values:
{ ^ [ YYYY-MM-DD [,] ] [ HH[:MM[:SS][.FFF]] [AM|PM] ] }
The following characters can be used as date delimiters: "-", "/".
Dot "." as date delimiter is not supported.
There is no limit on number of characters in YYYY, MM, DD, HH, MM,
SS, FFF parts. Important is only their value. This is the format
in semi PP notation:
{ ^ <YEAR> <sep:/-> <MONTH> <sep:/-> <DAY> [[<sep2:,>]
[ <HOUR> [ : <MIN> [ : <SEC> [ . <FRAQ> ] ] ] [AM|PP] ] }
In practice it allows to also parse xHarbour datetime constant
values with compatible conditions though xHarbour support onlu "/"
as date delimiter.
NOTE: there is one important difference to VFP and xHarbour in
decoding above format. In VFP and xHarbour when date part is
missing then it's set by default to: 1899-12-30 so this code:
{ ^ 12:00 }
gived the same results as:
{ ^ 1899/12/30 12:00 }
Harbour does not set any default date value when timestamp
constant value contains only time part.
If you want we can change it for strict VFP compatiblity.
Now this extension is enabled by default for testing. In the future
it will be probably covered by HB_COMPAT_FOXPRO macro.
* harbour/source/macro/macro.yyc
* harbour/source/macro/macro.y
* harbour/source/macro/macro.yyh
* harbour/source/macro/macrolex.c
+ added support for t"YYYY-MM-DD HH:MM:SS.fff" time stamp constant
to macro compiler
* harbour/include/hbmacro.h
* harbour/source/vm/macro.c
+ added new function:
void hb_macroGenPushTimeStamp( LONG lDate, LONG lTime, HB_COMP_DECL );
* harbour/include/hberrors.h
* harbour/source/compiler/hbgenerr.c
+ added new compile time error: "Invalid timestamp constant '%s'"
* harbour/source/compiler/cmdcheck.c
* use Harbour API timestamp functions instead of calling system
functions
* harbour/include/hbpcode.h
* harbour/source/compiler/hbfix.c
* harbour/source/compiler/hbpcode.c
* harbour/source/compiler/hbdead.c
* harbour/source/compiler/genc.c
* harbour/source/compiler/gencc.c
* harbour/source/compiler/hblbl.c
* harbour/source/compiler/hbstripl.c
* harbour/source/compiler/hbopt.c
+ added new PCODE HB_P_PUSHTIMESTAMP (replaced one unused PCODE value)
to store timestamp constant values in the PCODE
* harbour/include/hbcomp.h
* harbour/source/compiler/hbmain.c
+ added new function:
void hb_compGenPushTimeStamp( LONG lDate, LONG lTime, HB_COMP_DECL );
* harbour/include/hbexprop.h
* harbour/source/common/expropt1.c
+ added new C functions:
HB_EXPR_PTR hb_compExprNewTimeStamp( LONG, LONG, HB_COMP_DECL );
* harbour/include/hbexprb.c
* harbour/include/hbcompdf.h
* harbour/source/common/expropt2.c
+ added timestamp expressions support
+ added compile time optimization for timestamp expressions
* updated function optimization for timestamp expressions
* harbour/include/hbdate.h
* harbour/source/common/hbdate.c
* changed hb_dateMilliSeconds() to return UTC julian timestamp in
milliseconds
* changed existing seconds, time and timestamp functions to operate
on common OS specific functions to eliminate possible problems
with different OS time counters
+ added new functions to operates on time and timestamp values.
See source code for details.
+ harbour/source/rtl/cputime.c
* moved double hb_secondsCPU( int n ) function to separate file
* harbour/source/rtl/seconds.c
- removed old version of date/seconds functions
* harbour/source/vm/hashes.c
* harbour/source/vm/arrays.c
+ added support for timestamp values as hash item indexes
* harbour/source/vm/hashfunc.c
+ added support for find timestamp values in hash and array items
by simple date value in AScan(), hb_HScan(), hb_AScan() and hb_RAScan()
functions when exact comparison is not used.
* harbour/source/vm/asort.c
+ added support for sorting timestamp values
* harbour/source/vm/classes.c
+ added support for timestamp scallar classes
+ added support for timestamp typed instance variables
* harbour/source/vm/memvars.c
+ added support for timestamp values in .mem files
* harbour/source/vm/estack.c
+ show timestamp values in stack dump
* harbour/include/hbapi.h
* harbour/source/vm/arrays.c
+ added new C functions:
double hb_arrayGetTD( PHB_ITEM pArray, ULONG ulIndex );
BOOL hb_arraySetTD( PHB_ITEM pArray, ULONG ulIndex, double dTimeStamp )
BOOL hb_arrayGetTDT( PHB_ITEM pArray, ULONG ulIndex,
LONG * plJulian, LONG * plMilliSec );
BOOL hb_arraySetTDT( PHB_ITEM pArray, ULONG ulIndex,
LONG lJulian, LONG lMilliSec );
* harbour/include/hbapi.h
* harbour/source/vm/extend.c
+ accept timestamp items in date functions - use only date part of
timestamp value
+ added new C functions:
double hb_partd( int iParam, ... );
BOOL hb_partdt( LONG * plJulian, LONG * plMilliSec , int iParam, ... );
void hb_rettd( double dTimeStamp );
void hb_rettdt( LONG lJulian, LONG lMilliSec );
int hb_stortd( double dTimeStamp, int iParam, ... );
int hb_stortdt( LONG lJulian, LONG lMilliSec, int iParam, ... );
* harbour/include/hbapiitm.h
* harbour/source/vm/itemapi.c
+ accept timestamp items in date functions - use only date part of
timestamp value
+ added new C functions:
char * hb_itemGetTS( PHB_ITEM pItem, char * szDateTime );
PHB_ITEM hb_itemPutTS( PHB_ITEM pItem, const char * szDateTime );
double hb_itemGetTD( PHB_ITEM pItem );
PHB_ITEM hb_itemPutTD( PHB_ITEM pItem, double dTimeStamp )
BOOL hb_itemGetTDT( PHB_ITEM pItem, LONG * plJulian, LONG * plMilliSec );
PHB_ITEM hb_itemPutTDT( PHB_ITEM pItem, LONG lJulian, LONG lMilliSec );
+ support for timestamp items in hb_itemString(), hb_itemPadConv() and
hb_itemTypeStr() functions
* harbour/include/hbvm.h
* harbour/include/hbxvm.h
* harbour/include/hbapi.h
* harbour/source/vm/hvm.c
+ added HB_IT_TIMESTAMP items
* modified HB_IT_DATE internal item structure to use common structure
with HB_IT_TIMESTAMP - it simplifies HVM code and eliminates additional
RT conditions.
+ added HB_IS_TIMESTAMP() and ISTIMESTAMP() macros
+ added HB_IS_DATETIME() and ISDATETIME() macros - they return true
if item/parameter is DATE or TIMESTAMP type.
+ added void hb_vmPushTimeStamp( long lJulian, long lMilliSec );
and xhb_vmPushTimeStamp()
+ added support for timestamp values in relational operators:
<, <=, >, >=, =, ==
When two timestamp values are compared then VM compares date and
time parts in both values.
When date and timestamp values are used in <, <=, >, >=, = operations
then VM compares only date part in both values.
When date and timestamp values are used in == operation then VM
compares date part in both values and then check if time part
of timestamp value is 0.
+ added support for timestamp values in + and - math operations.
The following rules are used in timestamp arithmetic:
<t> + <t> => <t>
<t> - <t> => <n>
<t> + <n> => <t>
<n> + <t> => <t>
<t> - <n> => <t>
<d> + <t> => <t>
<t> + <d> => <t>
<d> - <t> => <n>
<t> - <d> => <n>
When number is result or argument of timestamp operation then the
its integer part is a number of day and fractional part is the time.
* harbour/source/rtl/dateshb.c
+ added new .prg functions to mange date and timestamp values:
HB_DATETIME() -> <tTimeStamp>
HB_CTOD( <cDate> [, <cDateFormat> ] ) -> <dDate>
HB_DTOC( <dDate> [, <cDateFormat> ] ) -> <cDate>
HB_NTOT( <nValue> ) -> <tTimeStamp>
HB_TTON( <tTimeStamp> ) -> <nValue>
HB_TTOC( <tTimeStamp>, [ <cDateFormat> ] [, <cTimeFormat> ] ) ->
<cTimeStamp>
HB_CTOT( <cTimeStamp>, [ <cDateFormat> ] [, <cTimeFormat> ] ) ->
<tTimeStamp>
HB_TTOS( <tTimeStamp> ) -> <cYYYYMMDDHHMMSSFFF>
HB_STOT( <cDateTime> ) -> <tTimeStamp>
<cDateTime> should be in one of the above form:
- "YYYYMMDDHHMMSSFFF"
- "YYYYMMDDHHMMSSFF"
- "YYYYMMDDHHMMSSF"
- "YYYYMMDDHHMMSS"
- "YYYYMMDDHHMM"
- "YYYYMMDDHH"
- "YYYYMMDD"
- "HHMMSSFFF"
- "HHMMSSF"
- "HHMMSS"
- "HHMM"
- "HH"
Important is number of digits.
HB_TSTOSTR( <tTimeStamp> ) -> <cTimeStamp> // YYYY-MM-DD HH:MM:SS.fff
HB_STRTOTS( <cTimeStamp> ) -> <tTimeStamp>
<cTimeStamp> should be in one of the above form:
YYYY-MM-DD [H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
YYYY-MM-DDT[H[H][:M[M][:S[S][.f[f[f[f]]]]]]] [PM|AM]
The folowing characters can be used as date delimiters: "-", "/", "."
T - is literal "T" - it's for XML timestamp format
if PM or AM is used HH is in range < 1 : 12 > otherwise
in range < 0 : 23 >
HB_HOUR( <tTimeStamp> ) -> <nHour>
HB_MINUTE( <tTimeStamp> ) -> <nMinute>
HB_SEC( <tTimeStamp> ) -> <nSeconds> // with milliseconds
* harbour/source/rtl/datec.c
+ accept timestamp parameters in CMONTH() and CDOW() functions
* harbour/source/rtl/empty.c
+ added support for timestamp items
* harbour/source/rtl/itemseri.c
+ added support for timestamp items serialization
* harbour/source/rtl/minmax.c
+ added support for timestamp values to MIN() and MAX() functions.
when only one of given parameters is timestamp value and other
is date value and date parts are equal then always date item
is returned as both MIN() or MAX() value.
* harbour/source/rtl/dates.c
+ added new C functions: hb_timeFormat(), hb_timeUnformat(),
hb_timeStampFormat(), hb_timeStampUnformat()
* harbour/source/rtl/valtype.c
+ added .prg functions: HB_ISDATETIME(), HB_ISTIMESTAMP()
* harbour/source/rtl/transfrm.c
+ added support for timestamp items formatting.
+ added new function modifier @T.
When @T is used without @D then only time part of timestamp value
is formatted and return.
When @D is used without @T then only date part of timestamp value
is formatted and return.
* harbour/source/rtl/tbrowse.prg
+ display timestamp values
* harbour/source/rtl/philes.c
+ accept timestamp value as second parameter of HB_FSETDATETIME()
function
+ store file data and time in second parameter of HB_FGETDATETIME()
as timestamp value.
Old parameters (2-dDate, 3-cTime) are still supported but please think
about removing them - they are redundant.
* harbour/source/rtl/filesys.c
* updated function names
* harbour/source/rdd/dbf1.c
+ added native support for time and timestamp fields
* harbour/include/hbrddcdx.h
* harbour/include/hbrddnsx.h
* harbour/source/rdd/dbfntx/dbfntx1.c
* harbour/source/rdd/dbfcdx/dbfcdx1.c
* harbour/source/rdd/dbfnsx/dbfnsx1.c
* harbour/source/rdd/dbffpt/dbffpt1.c
+ added support for indexing timestamp fields
+ added support for using DATE values with timestamp fields
which replicate HVM behavior.
SEEK and SEEKLAST with date value when active index is on
timestamp positions to 1-st or last record where date part
of indexed timesamp value is equal.
Settings scopes to date values when active index is on timestamp
value reduce the visible record range to these ones which have
date part of timestamp value in the range of dates values used
for scopes. It possible to mix date and timestamp values in scope
and set one scope to date value and the second to timesamp.
* harbour/source/rdd/sdf1.c
* harbour/source/rdd/delim1.c
+ added support for exporting timestamp fields
* harbour/source/rdd/dbsql.c
! fixed typo in logical value export
+ export timestamp fields.
Please update the format to given SQL syntax.
* harbour/contrib/hbct/files.c
+ changed SETFDATI() to optionally accept timestamp parameter
instead of two parameters dDate and cTime
* harbour/contrib/hbct/misc1.c
+ added timestamp support to XTOC() function
* harbour/contrib/hbct/misc2.c
+ added timestamp support to COMPLEMENT() function
* harbour/contrib/hbct/dattime2.c
+ accept timestamp values in ADDMONTH(), DOY(), ISLEAP(), QUARTER()
LASTDAYOM(), WEEK() functions
* harbour/contrib/hbmzip/hbmzip.c
+ updated HB_ZipFileCreate( hZip, cZipName, tDateTime, cTime, ... )
functions to optionaly accept timestamp value in 3-rd parameter
instead od dDate, and cTime in 3-rd and 4-th parameters.
+ updated HB_UnzipFileInfo( hUnzip, @cZipName, @tDateTime, @cTime, ... )
to return timestamp value in 3-rd parameter instead of date value.
TODO: Please think about removing 4-th parameter from:
HB_ZipFileCreate( hZip, cZipName, tDateTime, cTime, ... )
HB_UnzipFileInfo( hUnzip, @cZipName, @tDateTime, @cTime, ... )
Now it's redundant.
* harbour/contrib/hbmzip/readme.txt
* updated parameters description for above functions
* harbour/contrib/hbnf/descendn.c
+ added timestamp support to FT_DESCEND() function
* harbour/contrib/hbclipsm/date.c
+ accept timestamp values in DATEASAGE(), DATEASARRAY() and DATEISLEAP()
functions
* harbour/contrib/hbmisc/dates2.c
+ accept timestamp values in ISLEAPYEAR(), DAYSINMONTH(), EOM(), BOM(),
WOM(), WOY(), EOY() and BOY() functions
The following contrib files should be updated but I'm leaving it to
other developers who want to keep this code alive:
contrib/hbtip/utils.c
contrib/hbvpdf/hbvpdf.prg
contrib/hbvpdf/hbvpdft.prg
contrib/hbwin/win_dll.c
some minor cleanups if necessary and authors will find
timestamp values usable
contrib/hbole/ole2.c
contrib/hbwin/win_ole.c
add support for timestamp values in OLE
contrib/rddado/adordd.prg
contrib/rddads/ads1.c
contrib/rddads/adsx.c
contrib/rddsql/...
add support for timestamp values in RDDs
Warning: this implementation is not xHarbour compatible. There are many
important differences. Mostly on C level and used API. Please be careful
in porting xHarbour source code to Harbour.
891 lines
27 KiB
C
891 lines
27 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* The Date conversion module
|
|
*
|
|
* Copyright 1999 Antonio Linares <alinares@fivetech.com>
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
|
*
|
|
* As a special exception, the Harbour Project gives permission for
|
|
* additional uses of the text contained in its release of Harbour.
|
|
*
|
|
* The exception is that, if you link the Harbour libraries with other
|
|
* files to produce an executable, this does not by itself cause the
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
* Your use of that executable is in no way restricted on account of
|
|
* linking the Harbour library code into it.
|
|
*
|
|
* This exception does not however invalidate any other reasons why
|
|
* the executable file might be covered by the GNU General Public License.
|
|
*
|
|
* This exception applies only to the code released by the Harbour
|
|
* Project under the name Harbour. If you copy code from other
|
|
* Harbour Project or Free Software Foundation releases into a copy of
|
|
* Harbour, as the General Public License permits, the exception does
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
* anyone as to the status of such modified files, you must delete
|
|
* this exception notice from them.
|
|
*
|
|
* If you write modifications of your own for Harbour, it is your choice
|
|
* whether to permit this exception to apply to your modifications.
|
|
* If you do not wish that, delete this exception notice.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* The following parts are Copyright of the individual authors.
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* Copyright 1999-2001 Viktor Szakats <viktor.szakats@syenar.hu>
|
|
* hb_dateEncStr()
|
|
* hb_dateDecStr()
|
|
* hb_dateStrPut()
|
|
* hb_dateStrGet()
|
|
*
|
|
* Copyright 1999 Jose Lalin <dezac@corevia.com>
|
|
* hb_dateDOW()
|
|
*
|
|
* Copyright 2009 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* time/timestamp functions
|
|
*
|
|
* See doc/license.txt for licensing terms.
|
|
*
|
|
*/
|
|
|
|
#define HB_OS_WIN_USED
|
|
|
|
#include "hbapi.h"
|
|
#include "hbdate.h"
|
|
#if defined( HB_LONG_LONG_OFF )
|
|
# include "hbmath.h"
|
|
#endif
|
|
|
|
#include <time.h>
|
|
#if ( defined( HB_OS_BSD ) || defined( HB_OS_LINUX ) ) && !defined( __WATCOMC__ )
|
|
# include <sys/time.h>
|
|
#elif !defined( HB_OS_WIN )
|
|
# include <sys/timeb.h>
|
|
# if defined(_MSC_VER)
|
|
# define timeb _timeb
|
|
# define ftime _ftime
|
|
# endif
|
|
#endif
|
|
|
|
|
|
#ifdef HB_C52_STRICT
|
|
#define HB_DATE_YEAR_LIMIT 2999
|
|
#else
|
|
#define HB_DATE_YEAR_LIMIT 9999
|
|
#endif
|
|
|
|
#define HB_STR_DATE_BASE 1721060 /* 0000/01/01 */
|
|
#define HB_SYS_DATE_BASE 2440588 /* 1970/01/01 */
|
|
|
|
|
|
void hb_timeStampGetLocal( int * piYear, int * piMonth, int * piDay,
|
|
int * piHour, int * piMinutes,
|
|
int * piSeconds, int * piMSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampGetLocal(%p,%p,%p,%p,%p,%p,%p)", piYear, piMonth, piDay, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
#if defined(HB_OS_WIN)
|
|
{
|
|
SYSTEMTIME st;
|
|
|
|
GetLocalTime( &st );
|
|
|
|
*piYear = st.wYear;
|
|
*piMonth = st.wMonth;
|
|
*piDay = st.wDay;
|
|
*piHour = st.wHour;
|
|
*piMinutes = st.wMinute;
|
|
*piSeconds = st.wSecond;
|
|
*piMSec = st.wMilliseconds;
|
|
}
|
|
#else
|
|
{
|
|
struct tm st;
|
|
time_t seconds, millisecs;
|
|
|
|
# if defined( HB_OS_UNIX ) && !defined( __WATCOMC__ )
|
|
struct timeval tv;
|
|
gettimeofday( &tv, NULL );
|
|
seconds = tv.tv_sec;
|
|
millisecs = tv.tv_usec / 1000;
|
|
# else
|
|
struct timeb tb;
|
|
ftime( &tb );
|
|
seconds = tb.time;
|
|
millisecs = tb.millitm;
|
|
# endif
|
|
|
|
# if defined( HB_HAS_LOCALTIME_R )
|
|
localtime_r( &seconds, &st );
|
|
# else
|
|
st = *localtime( &seconds );
|
|
# endif
|
|
|
|
*piYear = st.tm_year + 1900;
|
|
*piMonth = st.tm_mon + 1;
|
|
*piDay = st.tm_mday;
|
|
*piHour = st.tm_hour;
|
|
*piMinutes = st.tm_min;
|
|
*piSeconds = st.tm_sec;
|
|
*piMSec = millisecs;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/* return UTC julian timestamp in milliseconds */
|
|
HB_ULONG hb_dateMilliSeconds( void )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateMilliSeconds()"));
|
|
|
|
#if defined(HB_OS_WIN)
|
|
{
|
|
SYSTEMTIME st;
|
|
GetSystemTime( &st );
|
|
return ( HB_ULONG ) hb_dateEncode( st.wYear, st.wMonth, st.wDay ) *
|
|
HB_MILLISECS_PER_DAY +
|
|
hb_timeEncode( st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
|
|
}
|
|
#elif defined( HB_OS_UNIX ) && !defined( __WATCOMC__ )
|
|
{
|
|
struct timeval tv;
|
|
gettimeofday( &tv, NULL );
|
|
return ( ( HB_ULONG ) tv.tv_sec +
|
|
( HB_ULONG ) HB_SYS_DATE_BASE * HB_SECONDS_PER_DAY ) * 1000 +
|
|
tv.tv_usec / 1000;
|
|
}
|
|
#else
|
|
{
|
|
struct timeb tb;
|
|
ftime( &tb );
|
|
return ( ( HB_ULONG ) tb.time +
|
|
( HB_ULONG ) HB_SYS_DATE_BASE * HB_SECONDS_PER_DAY ) * 1000 +
|
|
tb.time;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/* return local timestamp */
|
|
void hb_timeStampGet( LONG * plJulian, LONG * plMilliSec )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinute, iSeconds, iMillisec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampGet(%p,%p)", plJulian, plMilliSec));
|
|
|
|
hb_timeStampGetLocal( &iYear, &iMonth, &iDay,
|
|
&iHour, &iMinute, &iSeconds, &iMillisec );
|
|
*plJulian = hb_dateEncode( iYear, iMonth, iDay );
|
|
*plMilliSec = hb_timeEncode( iHour, iMinute, iSeconds, iMillisec );
|
|
}
|
|
|
|
double hb_dateSeconds( void )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinute, iSeconds, iMillisec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateSeconds()"));
|
|
|
|
hb_timeStampGetLocal( &iYear, &iMonth, &iDay,
|
|
&iHour, &iMinute, &iSeconds, &iMillisec );
|
|
return ( double ) hb_timeEncode( iHour, iMinute, iSeconds, iMillisec ) / 1000;
|
|
}
|
|
|
|
LONG hb_dateEncode( int iYear, int iMonth, int iDay )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateEncode(%d, %d, %d)", iYear, iMonth, iDay));
|
|
|
|
/* Perform date validation */
|
|
if( iYear >= 0 && iYear <= HB_DATE_YEAR_LIMIT &&
|
|
iMonth >= 1 && iMonth <= 12 &&
|
|
iDay >= 1 )
|
|
{
|
|
/* Month, year, and lower day limits are simple,
|
|
but upper day limit is dependent upon month and leap year */
|
|
static const int auiDayLimit[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
|
if( iDay <= auiDayLimit[ iMonth - 1 ] ||
|
|
( iDay == 29 && iMonth == 2 &&
|
|
( iYear & 3 ) == 0 && ( iYear % 100 != 0 || iYear % 400 == 0 ) ) )
|
|
{
|
|
int iFactor = ( iMonth < 3 ) ? -1 : 0;
|
|
|
|
return ( ( LONG )( iFactor + 4800 + iYear ) * 1461 / 4 ) +
|
|
( ( LONG )( iMonth - 2 - ( iFactor * 12 ) ) * 367 ) / 12 -
|
|
( ( LONG )( ( iFactor + 4900 + iYear ) / 100 ) * 3 / 4 ) +
|
|
( LONG ) iDay - 32075;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void hb_dateDecode( LONG lJulian, int *piYear, int *piMonth, int *piDay )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateDecode(%ld, %p, %p, %p)", lJulian, piYear, piMonth, piDay));
|
|
|
|
if( lJulian >= HB_STR_DATE_BASE )
|
|
{
|
|
LONG U, V, W, X;
|
|
|
|
lJulian += 68569;
|
|
W = ( lJulian * 4 ) / 146097;
|
|
lJulian -= ( ( 146097 * W ) + 3 ) / 4;
|
|
X = 4000 * ( lJulian + 1 ) / 1461001;
|
|
lJulian -= ( ( 1461 * X ) / 4 ) - 31;
|
|
V = 80 * lJulian / 2447;
|
|
U = V / 11;
|
|
|
|
*piYear = (int) ( X + U + ( W - 49 ) * 100 );
|
|
*piMonth = (int) ( V + 2 - ( U * 12 ) );
|
|
*piDay = (int) ( lJulian - ( 2447 * V / 80 ) );
|
|
}
|
|
else
|
|
{
|
|
*piYear =
|
|
*piMonth =
|
|
*piDay = 0;
|
|
}
|
|
}
|
|
|
|
void hb_dateStrPut( char * szDate, int iYear, int iMonth, int iDay )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateStrPut(%p, %d, %d, %d)", szDate, iYear, iMonth, iDay));
|
|
|
|
if( iYear >= 0 && iMonth > 0 && iDay > 0 )
|
|
{
|
|
szDate[ 0 ] = ( char ) ( ( ( iYear / 1000 ) % 10 ) + '0' );
|
|
szDate[ 1 ] = ( char ) ( ( ( iYear / 100 ) % 10 ) + '0' );
|
|
szDate[ 2 ] = ( char ) ( ( ( iYear / 10 ) % 10 ) + '0' );
|
|
szDate[ 3 ] = ( char ) ( ( iYear % 10 ) + '0' );
|
|
|
|
szDate[ 4 ] = ( char ) ( ( iMonth / 10 ) + '0' );
|
|
szDate[ 5 ] = ( char ) ( ( iMonth % 10 ) + '0' );
|
|
|
|
szDate[ 6 ] = ( char ) ( ( iDay / 10 ) + '0' );
|
|
szDate[ 7 ] = ( char ) ( ( iDay % 10 ) + '0' );
|
|
}
|
|
else
|
|
{
|
|
memset( szDate, '0', 8 );
|
|
}
|
|
}
|
|
|
|
void hb_dateStrGet( const char * szDate, int * piYear, int * piMonth, int * piDay )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateStrGet(%s, %p, %p, %p)", szDate, piYear, piMonth, piDay));
|
|
|
|
#if defined( HB_C52_STRICT ) || 1
|
|
if( szDate )
|
|
#else
|
|
if( szDate &&
|
|
szDate[ 0 ] >= '0' && szDate[ 0 ] <= '9' &&
|
|
szDate[ 1 ] >= '0' && szDate[ 1 ] <= '9' &&
|
|
szDate[ 2 ] >= '0' && szDate[ 2 ] <= '9' &&
|
|
szDate[ 3 ] >= '0' && szDate[ 3 ] <= '9' &&
|
|
szDate[ 4 ] >= '0' && szDate[ 4 ] <= '9' &&
|
|
szDate[ 5 ] >= '0' && szDate[ 5 ] <= '9' &&
|
|
szDate[ 6 ] >= '0' && szDate[ 6 ] <= '9' &&
|
|
szDate[ 7 ] >= '0' && szDate[ 7 ] <= '9' )
|
|
#endif
|
|
{
|
|
/* Date string has correct length, so attempt to convert */
|
|
*piYear = ( ( ( int ) ( szDate[ 0 ] - '0' ) * 10 +
|
|
( int ) ( szDate[ 1 ] - '0' ) ) * 10 +
|
|
( int ) ( szDate[ 2 ] - '0' ) ) * 10 +
|
|
( int ) ( szDate[ 3 ] - '0' );
|
|
*piMonth = ( szDate[ 4 ] - '0' ) * 10 + ( szDate[ 5 ] - '0' );
|
|
*piDay = ( szDate[ 6 ] - '0' ) * 10 + ( szDate[ 7 ] - '0' );
|
|
}
|
|
else
|
|
{
|
|
/* Date string missing or bad length, so force an empty date */
|
|
*piYear =
|
|
*piMonth =
|
|
*piDay = 0;
|
|
}
|
|
}
|
|
|
|
/* This function always closes the date with a zero byte, so it needs a
|
|
9 character long buffer. */
|
|
|
|
char * hb_dateDecStr( char * szDate, LONG lJulian )
|
|
{
|
|
int iYear, iMonth, iDay;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateDecStr(%p, %ld)", szDate, lJulian));
|
|
|
|
if( lJulian <= 0 )
|
|
{
|
|
memset( szDate, ' ', 8 );
|
|
}
|
|
else
|
|
{
|
|
hb_dateDecode( lJulian, &iYear, &iMonth, &iDay );
|
|
hb_dateStrPut( szDate, iYear, iMonth, iDay );
|
|
}
|
|
szDate[ 8 ] = '\0';
|
|
|
|
return szDate;
|
|
}
|
|
|
|
LONG hb_dateEncStr( const char * szDate )
|
|
{
|
|
int iYear, iMonth, iDay;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateEncStr(%s)", szDate));
|
|
|
|
hb_dateStrGet( szDate, &iYear, &iMonth, &iDay );
|
|
|
|
return hb_dateEncode( iYear, iMonth, iDay );
|
|
}
|
|
|
|
int hb_dateJulianDOW( LONG lJulian )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateJulianDOW(%ld)", lJulian));
|
|
|
|
if( lJulian >= HB_STR_DATE_BASE )
|
|
return ( int ) ( ( lJulian + 1 ) % 7 ) + 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
int hb_dateDOW( int iYear, int iMonth, int iDay )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateDOW(%d, %d, %d)", iYear, iMonth, iDay));
|
|
|
|
if( iMonth < 3 )
|
|
{
|
|
iMonth += 13;
|
|
iYear--;
|
|
}
|
|
else
|
|
iMonth++;
|
|
|
|
return ( iDay + 26 * iMonth / 10 +
|
|
iYear + iYear / 4 - iYear / 100 + iYear / 400 + 6 ) % 7 + 1;
|
|
}
|
|
|
|
void hb_dateToday( int * piYear, int * piMonth, int * piDay )
|
|
{
|
|
int iHour, iMinute, iSeconds, iMillisec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateToday(%p,%p,%p)", piYear, piMonth, piDay));
|
|
|
|
hb_timeStampGetLocal( piYear, piMonth, piDay,
|
|
&iHour, &iMinute, &iSeconds, &iMillisec );
|
|
}
|
|
|
|
/* NOTE: The passed buffer must be at least 9 chars long */
|
|
|
|
void hb_dateTimeStr( char * pszTime )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinute, iSeconds, iMillisec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStr(%p)", pszTime));
|
|
|
|
hb_timeStampGetLocal( &iYear, &iMonth, &iDay,
|
|
&iHour, &iMinute, &iSeconds, &iMillisec );
|
|
hb_snprintf( pszTime, 9, "%02d:%02d:%02d", iHour, iMinute, iSeconds );
|
|
}
|
|
|
|
/* functions to operate on time and timestamp values */
|
|
|
|
LONG hb_timeEncode( int iHour, int iMinutes, int iSeconds, int iMSec )
|
|
{
|
|
LONG lMilliSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeEncode(%d, %d, %d, %d)", iHour, iMinutes, iSeconds, iMSec));
|
|
|
|
if( iHour >= 0 && iHour < 24 &&
|
|
iMinutes >= 0 && iMinutes < 60 &&
|
|
iSeconds >= 0 && iSeconds < 60 &&
|
|
iMSec >= 0 && iMSec < 1000 ) /* <= intentionally for rounded milliseconds values */
|
|
{
|
|
lMilliSec = ( ( LONG ) ( iHour * 60 + iMinutes ) * 60 + iSeconds ) *
|
|
1000 + iMSec;
|
|
}
|
|
else
|
|
lMilliSec = 0;
|
|
|
|
return lMilliSec;
|
|
}
|
|
|
|
void hb_timeDecode( LONG lMilliSec, int * piHour, int * piMinutes,
|
|
int * piSeconds, int * piMSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeDecode(%ld, %p, %p, %p, %p)", lMilliSec, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
if( lMilliSec <= 0 )
|
|
{
|
|
*piHour = *piMinutes = *piSeconds = *piMSec = 0;
|
|
}
|
|
else
|
|
{
|
|
*piMSec = lMilliSec % 1000;
|
|
lMilliSec /= 1000;
|
|
*piSeconds = lMilliSec % 60;
|
|
lMilliSec /= 60;
|
|
*piMinutes = lMilliSec % 60;
|
|
lMilliSec /= 60;
|
|
if( lMilliSec >= 24 )
|
|
*piHour = *piMinutes = *piSeconds = *piMSec = 0;
|
|
else
|
|
*piHour = ( int ) lMilliSec;
|
|
}
|
|
}
|
|
|
|
/* This function always closes the time with a zero byte, so it needs a
|
|
* 13 character long buffer to store time in format "hh:mm:ss.fff"
|
|
*/
|
|
char * hb_timeStr( char * szTime, LONG lMilliSec )
|
|
{
|
|
int iHour, iMinutes, iSeconds, iMSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStr(%p, %ld)", szTime, lMilliSec));
|
|
|
|
hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec );
|
|
hb_snprintf( szTime, 13, "%02d:%02d:%02d.%03d",
|
|
iHour, iMinutes, iSeconds, iMSec );
|
|
|
|
return szTime;
|
|
}
|
|
|
|
BOOL hb_timeStrGet( const char * szTime,
|
|
int * piHour, int * piMinutes,
|
|
int * piSeconds, int * piMSec )
|
|
{
|
|
int iHour, iMinutes, iSeconds, iMSec, iBlocks;
|
|
BOOL fValid;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStrGet(%s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
iHour = iMinutes = iSeconds = iMSec = iBlocks = 0;
|
|
fValid = FALSE;
|
|
|
|
if( szTime )
|
|
{
|
|
while( HB_ISSPACE( *szTime ) )
|
|
++szTime;
|
|
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
{
|
|
iHour = ( *szTime++ - '0' );
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
iHour = iHour * 10 + ( *szTime++ - '0' );
|
|
if( *szTime == ':' && HB_ISDIGIT( szTime[ 1 ] ) )
|
|
{
|
|
++iBlocks;
|
|
++szTime;
|
|
iMinutes = ( *szTime++ - '0' );
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
iMinutes = iMinutes * 10 + ( *szTime++ - '0' );
|
|
if( *szTime == ':' && HB_ISDIGIT( szTime[ 1 ] ) )
|
|
{
|
|
++iBlocks;
|
|
++szTime;
|
|
iSeconds = ( *szTime++ - '0' );
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
iSeconds = iSeconds * 10 + ( *szTime++ - '0' );
|
|
if( *szTime == '.' && HB_ISDIGIT( szTime[ 1 ] ) )
|
|
{
|
|
++iBlocks;
|
|
++szTime;
|
|
iMSec = ( *szTime++ - '0' );
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
{
|
|
iMSec = iMSec * 10 + ( *szTime++ - '0' );
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
iMSec = iMSec * 10 + ( *szTime++ - '0' );
|
|
}
|
|
if( HB_ISDIGIT( *szTime ) )
|
|
++szTime;
|
|
}
|
|
}
|
|
}
|
|
while( HB_ISSPACE( *szTime ) )
|
|
++szTime;
|
|
if( ( szTime[ 0 ] == 'p' || szTime[ 0 ] == 'P' ) &&
|
|
( szTime[ 1 ] == 'm' || szTime[ 1 ] == 'M' ) )
|
|
{
|
|
++iBlocks;
|
|
szTime += 2;
|
|
if( iHour == 0 )
|
|
iHour = 24; /* wrong time */
|
|
else if( iHour != 12 )
|
|
iHour += 12;
|
|
}
|
|
else if( ( szTime[ 0 ] == 'a' || szTime[ 0 ] == 'A' ) &&
|
|
( szTime[ 1 ] == 'm' || szTime[ 1 ] == 'M' ) )
|
|
{
|
|
++iBlocks;
|
|
szTime += 2;
|
|
if( iHour == 0 )
|
|
iHour = 24; /* wrong time */
|
|
else if( iHour == 12 )
|
|
iHour = 0;
|
|
}
|
|
while( HB_ISSPACE( *szTime ) )
|
|
++szTime;
|
|
if( *szTime == 0 && iBlocks > 0 &&
|
|
iHour < 24 && iMinutes < 60 && iSeconds < 60 )
|
|
fValid = TRUE;
|
|
else
|
|
iHour = iMinutes = iSeconds = iMSec = 0;
|
|
}
|
|
}
|
|
|
|
if( piHour )
|
|
*piHour = iHour;
|
|
if( piMinutes )
|
|
*piMinutes = iMinutes;
|
|
if( piSeconds )
|
|
*piSeconds = iSeconds;
|
|
if( piMSec )
|
|
*piMSec = iMSec;
|
|
|
|
return fValid;
|
|
}
|
|
|
|
void hb_timeStrRawGet( const char * szTime,
|
|
int * piHour, int * piMinutes,
|
|
int * piSeconds, int * piMSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStrRawGet(%s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
*piHour = *piMinutes = *piSeconds = *piMSec = 0;
|
|
|
|
if( szTime )
|
|
{
|
|
int iLen = 0;
|
|
|
|
while( iLen < 10 && HB_ISDIGIT( szTime[ iLen ] ) )
|
|
++iLen;
|
|
|
|
if( iLen >= 2 && ( ( iLen & 1 ) == 0 || iLen == 7 || iLen == 9 ) )
|
|
{
|
|
*piHour = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
|
|
szTime += 2;
|
|
iLen -= 2;
|
|
if( iLen >= 2 )
|
|
{
|
|
*piMinutes = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
|
|
szTime += 2;
|
|
iLen -= 2;
|
|
if( iLen >= 2 )
|
|
{
|
|
*piSeconds = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
|
|
szTime += 2;
|
|
iLen -= 2;
|
|
switch( iLen )
|
|
{
|
|
case 4:
|
|
case 3:
|
|
*piMSec = ( ( int ) ( szTime[ 0 ] - '0' ) * 10 +
|
|
( int ) ( szTime[ 1 ] - '0' ) ) * 10 +
|
|
( int ) ( szTime[ 2 ] - '0' );
|
|
break;
|
|
case 2:
|
|
*piMSec = ( ( int ) ( szTime[ 0 ] - '0' ) * 10 +
|
|
( int ) ( szTime[ 1 ] - '0' ) ) * 10;
|
|
break;
|
|
case 1:
|
|
*piMSec = ( int ) ( szTime[ 0 ] - '0' ) * 100;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* This function always closes the time with a zero byte, so it needs a
|
|
* 18 character long buffer to store time in format "YYYYMMDDhhmmssfff"
|
|
* with trailing 0 byte.
|
|
*/
|
|
char * hb_timeStampStrRawPut( char * szDateTime, LONG lJulian, LONG lMilliSec )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStrRawPut(%p, %ld, %ld)", szDateTime, lJulian, lMilliSec));
|
|
|
|
hb_dateDecode( lJulian, &iYear, &iMonth, &iDay );
|
|
hb_dateStrPut( szDateTime, iYear, iMonth, iDay );
|
|
hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec );
|
|
hb_snprintf( szDateTime + 8, 10, "%02d%02d%02d%03d",
|
|
iHour, iMinutes, iSeconds, iMSec );
|
|
|
|
return szDateTime;
|
|
}
|
|
|
|
void hb_timeStampStrRawGet( const char * szDateTime, LONG * plJulian, LONG * plMilliSec )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec, iLen;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStrRawGet(%s, %p, %p)", szDateTime, plJulian, plMilliSec));
|
|
|
|
*plJulian = *plMilliSec = 0;
|
|
|
|
iLen = 0;
|
|
while( iLen < 10 && HB_ISDIGIT( szDateTime[ iLen ] ) )
|
|
++iLen;
|
|
|
|
if( iLen == 8 || iLen >= 10 )
|
|
{
|
|
hb_dateStrGet( szDateTime, &iYear, &iMonth, &iDay );
|
|
*plJulian = hb_dateEncode( iYear, iMonth, iDay );
|
|
szDateTime += 8;
|
|
iLen -= 8;
|
|
}
|
|
|
|
if( iLen >= 2 )
|
|
{
|
|
hb_timeStrRawGet( szDateTime, &iHour, &iMinutes, &iSeconds, &iMSec );
|
|
*plMilliSec = hb_timeEncode( iHour, iMinutes, iSeconds, iMSec );
|
|
}
|
|
}
|
|
|
|
/* This function always closes the time with a zero byte.
|
|
* It needs a 24 character long buffer for full datetime representation
|
|
* "YYYY-MM-DD hh:mm:ss.fff"
|
|
*/
|
|
char * hb_timeStampStr( char * szDateTime, LONG lJulian, LONG lMilliSec )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStr(%p, %ld, %ld)", szDateTime, lJulian, lMilliSec));
|
|
|
|
hb_dateDecode( lJulian, &iYear, &iMonth, &iDay );
|
|
hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec );
|
|
hb_snprintf( szDateTime, 24, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
|
|
iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec );
|
|
szDateTime[ 23 ] = '\0';
|
|
|
|
return szDateTime;
|
|
}
|
|
|
|
BOOL hb_timeStampStrGet( const char * szDateTime,
|
|
int * piYear, int * piMonth, int * piDay,
|
|
int * piHour, int * piMinutes, int * piSeconds,
|
|
int * piMSec )
|
|
{
|
|
int iYear, iMonth, iDay;
|
|
BOOL fValid;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStrGet(%s, %p, %p, %p, %p, %p, %p, %p)", szDateTime, piYear, piMonth, piDay, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
iYear = iMonth = iDay = 0;
|
|
fValid = FALSE;
|
|
|
|
if( szDateTime )
|
|
{
|
|
while( HB_ISSPACE( *szDateTime ) )
|
|
++szDateTime;
|
|
if( HB_ISDIGIT( szDateTime[ 0 ] ) && HB_ISDIGIT( szDateTime[ 1 ] ) &&
|
|
HB_ISDIGIT( szDateTime[ 2 ] ) && HB_ISDIGIT( szDateTime[ 3 ] ) &&
|
|
( szDateTime[ 4 ] == '-' || szDateTime[ 4 ] == '/' || szDateTime[ 4 ] == '.' ) &&
|
|
HB_ISDIGIT( szDateTime[ 5 ] ) && HB_ISDIGIT( szDateTime[ 6 ] ) &&
|
|
szDateTime[ 7 ] == szDateTime[ 4 ] &&
|
|
HB_ISDIGIT( szDateTime[ 9 ] ) && HB_ISDIGIT( szDateTime[ 9 ] ) &&
|
|
!HB_ISDIGIT( szDateTime[ 10 ] ) )
|
|
{
|
|
iYear = ( ( ( int ) ( szDateTime[ 0 ] - '0' ) * 10 +
|
|
( int ) ( szDateTime[ 1 ] - '0' ) ) * 10 +
|
|
( int ) ( szDateTime[ 2 ] - '0' ) ) * 10 +
|
|
( int ) ( szDateTime[ 3 ] - '0' );
|
|
iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' );
|
|
iDay = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' );
|
|
if( hb_dateEncode( iYear, iMonth, iDay ) != 0 )
|
|
{
|
|
szDateTime += 10;
|
|
if( *szDateTime == 'T' || *szDateTime == 't' )
|
|
{
|
|
if( HB_ISDIGIT( szDateTime[ 1 ] ) )
|
|
++szDateTime;
|
|
}
|
|
else
|
|
{
|
|
if( *szDateTime == ',' )
|
|
++szDateTime;
|
|
while( HB_ISSPACE( *szDateTime ) )
|
|
++szDateTime;
|
|
if( *szDateTime == '\0' )
|
|
szDateTime = NULL;
|
|
fValid = TRUE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
iYear = iMonth = iDay = 0;
|
|
szDateTime = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( !hb_timeStrGet( szDateTime, piHour, piMinutes, piSeconds, piMSec ) )
|
|
{
|
|
if( szDateTime )
|
|
fValid = FALSE;
|
|
}
|
|
else
|
|
fValid = TRUE;
|
|
|
|
if( piYear )
|
|
*piYear = iYear;
|
|
if( piMonth )
|
|
*piMonth = iMonth;
|
|
if( piDay )
|
|
*piDay = iDay;
|
|
|
|
return fValid;
|
|
}
|
|
|
|
BOOL hb_timeStampStrGetDT( const char * szDateTime,
|
|
LONG * plJulian, LONG * plMilliSec )
|
|
{
|
|
int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec;
|
|
BOOL fValid;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStrGetDT(%s, %p, %p)", szDateTime, plJulian, plMilliSec));
|
|
|
|
fValid = hb_timeStampStrGet( szDateTime, &iYear, &iMonth, &iDay,
|
|
&iHour, &iMinutes, &iSeconds, &iMSec );
|
|
if( plJulian )
|
|
*plJulian = hb_dateEncode( iYear, iMonth, iDay );
|
|
if( plMilliSec )
|
|
*plMilliSec = hb_timeEncode( iHour, iMinutes, iSeconds, iMSec );
|
|
|
|
return fValid;
|
|
}
|
|
|
|
double hb_timeStampPackDT( LONG lJulian, LONG lMilliSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampPackDT(%ld, %ld)", lJulian, lMilliSec));
|
|
|
|
return ( double ) lJulian +
|
|
( double ) lMilliSec / HB_MILLISECS_PER_DAY;
|
|
}
|
|
|
|
void hb_timeStampUnpackDT( double dTimeStamp,
|
|
LONG * plJulian, LONG * plMilliSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampUnpackDT(%f, %p, %p)", dTimeStamp, plJulian, plMilliSec));
|
|
|
|
{
|
|
#if defined( HB_LONG_LONG_OFF )
|
|
double dJulian, dTime;
|
|
|
|
dTime = modf( dTimeStamp + 0.5 / HB_MILLISECS_PER_DAY, &dJulian );
|
|
if( plJulian )
|
|
*plJulian = ( LONG ) dJulian;
|
|
if( plMilliSec )
|
|
*plMilliSec = ( LONG ) ( dTime * HB_MILLISECS_PER_DAY );
|
|
#else
|
|
LONGLONG llMilliSec = ( LONGLONG ) ( dTimeStamp * HB_MILLISECS_PER_DAY + 0.5 );
|
|
if( plJulian )
|
|
*plJulian = ( LONG ) ( llMilliSec / HB_MILLISECS_PER_DAY );
|
|
if( plMilliSec )
|
|
*plMilliSec = ( LONG ) ( llMilliSec % HB_MILLISECS_PER_DAY );
|
|
#endif
|
|
}
|
|
}
|
|
|
|
double hb_timeStampPack( int iYear, int iMonth, int iDay,
|
|
int iHour, int iMinutes, int iSeconds, int iMSec )
|
|
{
|
|
double dTimeStamp = 0;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampPack(%d, %d, %d, %d, %d, %d, %d)", iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec));
|
|
|
|
if( iHour >= 0 && iHour < 24 &&
|
|
iMinutes >= 0 && iMinutes < 60 &&
|
|
iSeconds >= 0 && iSeconds < 60 &&
|
|
iMSec >= 0 && iMSec < 1000 )
|
|
{
|
|
LONG lJulian = hb_dateEncode( iYear, iMonth, iDay );
|
|
|
|
if( lJulian != 0 || ( iYear == 0 && iMonth == 0 && iDay == 0 ) )
|
|
{
|
|
dTimeStamp = ( double ) lJulian +
|
|
( double ) ( ( ( LONG ) ( iHour * 60 + iMinutes ) * 60 +
|
|
iSeconds ) * 1000 + iMSec ) /
|
|
HB_SECONDS_PER_DAY;
|
|
}
|
|
}
|
|
return dTimeStamp;
|
|
}
|
|
|
|
void hb_timeStampUnpack( double dTimeStamp,
|
|
int * piYear, int * piMonth, int * piDay,
|
|
int * piHour, int * piMinutes, int * piSeconds,
|
|
int * piMSec )
|
|
{
|
|
LONG lJulian, lMilliSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampUnpack(%f, %p, %p, %p, %p, %p, %p, %p)", dTimeStamp, piYear, piMonth, piDay, piHour, piMinutes, piSeconds, piMSec));
|
|
|
|
hb_timeStampUnpackDT( dTimeStamp, &lJulian, &lMilliSec );
|
|
hb_dateDecode( lJulian, piYear, piMonth, piDay );
|
|
hb_timeDecode( lMilliSec, piHour, piMinutes, piSeconds, piMSec );
|
|
}
|
|
|
|
double hb_timeStampPackD( int iYear, int iMonth, int iDay,
|
|
int iHour, int iMinutes, double dSeconds )
|
|
{
|
|
double dTimeStamp = 0;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampPackD(%d, %d, %d, %d, %d, %f)", iYear, iMonth, iDay, iHour, iMinutes, dSeconds));
|
|
|
|
if( iHour >= 0 && iHour < 24 &&
|
|
iMinutes >= 0 && iMinutes < 60 &&
|
|
dSeconds >= 0 && dSeconds < 60 )
|
|
{
|
|
LONG lJulian = hb_dateEncode( iYear, iMonth, iDay );
|
|
|
|
if( lJulian != 0 || ( iYear == 0 && iMonth == 0 && iDay == 0 ) )
|
|
{
|
|
dTimeStamp = ( double ) lJulian +
|
|
( double ) ( ( ( iHour * 60 + iMinutes ) * 60 ) +
|
|
dSeconds ) / HB_SECONDS_PER_DAY;
|
|
}
|
|
}
|
|
return dTimeStamp;
|
|
}
|
|
|
|
void hb_timeStampUnpackD( double dTimeStamp,
|
|
int * piYear, int * piMonth, int * piDay,
|
|
int * piHour, int * piMinutes, double * pdSeconds )
|
|
{
|
|
LONG lJulian, lMilliSec;
|
|
int iSeconds, iMSec;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampUnpackD(%f, %p, %p, %p, %p, %p, %p)", dTimeStamp, piYear, piMonth, piDay, piHour, piMinutes, pdSeconds));
|
|
|
|
hb_timeStampUnpackDT( dTimeStamp, &lJulian, &lMilliSec );
|
|
hb_dateDecode( lJulian, piYear, piMonth, piDay );
|
|
hb_timeDecode( lMilliSec, piHour, piMinutes, &iSeconds, &iMSec );
|
|
|
|
if( pdSeconds )
|
|
*pdSeconds = ( double ) iSeconds + ( double ) iMSec / 1000;
|
|
}
|