2009-07-29 22:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbtip/utils.c
* contrib/hbtip/tests/tiptime.prg
! Reworked TIP_TIMESTAMP():
! Applied fix from xhb. (with cleanups/optimizations and without
newly introduced bug)
+ Added support for DATETIME type as first parameter.
(at the same time second numeric time parameter is deprecated)
% Simplified code, more optimal API/memory usage.
* Second parameter will always override default time, if passed.
This is a little bit different, but more natural behavior than
before.
+ Replaced meaningless test code with some better one.
; NOTE: We should probably add some core functions to detect TZ offset.
* examples/httpsrv/uhttpdc.c
! Applied above fix/cleanups to HB_UTCOFFSET().
* source/common/hbdate.c
* Minor formatting.
This commit is contained in:
@@ -17,6 +17,27 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2009-07-29 22:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* contrib/hbtip/utils.c
|
||||
* contrib/hbtip/tests/tiptime.prg
|
||||
! Reworked TIP_TIMESTAMP():
|
||||
! Applied fix from xhb. (with cleanups/optimizations and without
|
||||
newly introduced bug)
|
||||
+ Added support for DATETIME type as first parameter.
|
||||
(at the same time second numeric time parameter is deprecated)
|
||||
% Simplified code, more optimal API/memory usage.
|
||||
* Second parameter will always override default time, if passed.
|
||||
This is a little bit different, but more natural behavior than
|
||||
before.
|
||||
+ Replaced meaningless test code with some better one.
|
||||
; NOTE: We should probably add some core functions to detect TZ offset.
|
||||
|
||||
* examples/httpsrv/uhttpdc.c
|
||||
! Applied above fix/cleanups to HB_UTCOFFSET().
|
||||
|
||||
* source/common/hbdate.c
|
||||
* Minor formatting.
|
||||
|
||||
2009-07-29 18:03 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* utils/hbmk2/hbmk2.prg
|
||||
* Minor formatting.
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/******************************************
|
||||
* TIP test
|
||||
* timestamp encoding and decoding
|
||||
*
|
||||
* Usage:
|
||||
* base64test "timestamp"
|
||||
*****/
|
||||
/*
|
||||
* Copyright 2009 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* www - http://www.harbour-project.org
|
||||
*/
|
||||
|
||||
PROCEDURE MAIN( cTimeStamp )
|
||||
#include "simpleio.ch"
|
||||
|
||||
IF cTimeStamp == NIL
|
||||
? "Now is:", TIP_Timestamp()
|
||||
?
|
||||
ENDIF
|
||||
RETURN
|
||||
PROCEDURE Main()
|
||||
|
||||
? ">" + TIP_TIMESTAMP() + "<"
|
||||
? ">" + TIP_TIMESTAMP( NIL, 200 ) + "<"
|
||||
? ">" + TIP_TIMESTAMP( Date() ) + "<"
|
||||
? ">" + TIP_TIMESTAMP( Date(), 200 ) + "<"
|
||||
? ">" + TIP_TIMESTAMP( hb_DateTime() ) + "<"
|
||||
? ">" + TIP_TIMESTAMP( hb_DateTime(), 200 ) + "<"
|
||||
|
||||
RETURN
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
*
|
||||
* Copyright 1999-2001 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* hb_strAtI()
|
||||
* TIP_TIMESTAMP() rework
|
||||
* cleanup
|
||||
*
|
||||
* See COPYING for licensing terms.
|
||||
*
|
||||
@@ -83,50 +85,54 @@
|
||||
|
||||
HB_FUNC( TIP_TIMESTAMP )
|
||||
{
|
||||
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
|
||||
ULONG ulHour = hb_parnl( 2 );
|
||||
int nLen;
|
||||
char * szRet = ( char * ) hb_xgrab( 64 );
|
||||
char szRet[ 64 ];
|
||||
|
||||
/* sadly, many strftime windows implementations are broken */
|
||||
#if defined( HB_OS_WIN )
|
||||
|
||||
TIME_ZONE_INFORMATION tzInfo;
|
||||
static const char * s_days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static const char * s_months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
int iYear, iMonth, iDay, iHour, iMinute, iSecond, iMSec, iTZBias;
|
||||
|
||||
if( GetTimeZoneInformation( &tzInfo ) == TIME_ZONE_ID_INVALID )
|
||||
tzInfo.Bias = 0;
|
||||
|
||||
if( ! pDate )
|
||||
/* Detect TZ bias */
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
TIME_ZONE_INFORMATION tzInfo;
|
||||
DWORD retval = GetTimeZoneInformation( &tzInfo );
|
||||
|
||||
GetLocalTime( &st );
|
||||
|
||||
hb_snprintf( szRet, 64, "%s, %u %s %u %02u:%02u:%02u %+03d%02d",
|
||||
s_days[ st.wDayOfWeek ], st.wDay, s_months[ st.wMonth - 1 ],
|
||||
st.wYear,
|
||||
st.wHour, st.wMinute, st.wSecond,
|
||||
( int ) ( tzInfo.Bias / 60 ),
|
||||
( int ) ( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
|
||||
if( retval == TIME_ZONE_ID_INVALID )
|
||||
iTZBias = 0;
|
||||
else
|
||||
iTZBias = -( tzInfo.Bias + ( retval == TIME_ZONE_ID_STANDARD ? tzInfo.StandardBias : tzInfo.DaylightBias ) );
|
||||
}
|
||||
|
||||
if( HB_ISDATE( 1 ) )
|
||||
{
|
||||
hb_dateDecode( hb_pardl( 1 ), &iYear, &iMonth, &iDay );
|
||||
iHour = iMinute = iSecond = 0;
|
||||
}
|
||||
else if( HB_ISDATETIME( 1 ) )
|
||||
hb_timeStampUnpack( hb_partd( 1 ), &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond, &iMSec );
|
||||
else
|
||||
hb_timeStampGetLocal( &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond, &iMSec );
|
||||
|
||||
/* For compatibility */
|
||||
if( HB_ISNUM( 2 ) )
|
||||
{
|
||||
long lDate = hb_itemGetDL( pDate );
|
||||
int iYear, iMonth, iDay;
|
||||
ULONG ulHour = hb_parnl( 2 );
|
||||
|
||||
hb_dateDecode( lDate, &iYear, &iMonth, &iDay );
|
||||
|
||||
hb_snprintf( szRet, 64, "%s, %d %s %d %02u:%02u:%02u %+03d%02d",
|
||||
s_days[ hb_dateDOW( iYear, iMonth, iDay ) - 1 ], iDay,
|
||||
s_months[ iMonth - 1 ], iYear,
|
||||
( unsigned int )( ulHour / 3600 ), ( unsigned int )( ( ulHour % 3600 ) / 60 ), ( unsigned int ) ( ulHour % 60 ),
|
||||
( int ) ( tzInfo.Bias / 60 ),
|
||||
( int ) ( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
|
||||
iHour = ( int ) ( ulHour / 3600 );
|
||||
iMinute = ( int ) ( ( ulHour % 3600 ) / 60 );
|
||||
iSecond = ( int ) ( ulHour % 60 );
|
||||
}
|
||||
|
||||
nLen = strlen( szRet );
|
||||
{
|
||||
static const char * s_days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static const char * s_months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
|
||||
hb_snprintf( szRet, sizeof( szRet ), "%s, %d %s %d %02d:%02d:%02d %+03d%02d",
|
||||
s_days[ hb_dateDOW( iYear, iMonth, iDay ) - 1 ], iDay, s_months[ iMonth - 1 ],
|
||||
iYear, iHour, iMinute, iSecond,
|
||||
( int ) iTZBias / 60,
|
||||
( int ) iTZBias % 60 );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -141,39 +147,45 @@ HB_FUNC( TIP_TIMESTAMP )
|
||||
tmTime = *localtime( ¤t );
|
||||
#endif
|
||||
|
||||
if( pDate )
|
||||
if( HB_ISDATE( 1 ) )
|
||||
{
|
||||
char szDate[ 9 ];
|
||||
int iYear, iMonth, iDay;
|
||||
|
||||
hb_itemGetDS( pDate, szDate );
|
||||
hb_dateDecode( hb_pardl( 1 ), &iYear, &iMonth, &iDay );
|
||||
|
||||
tmTime.tm_year = (
|
||||
( szDate[ 0 ] - '0' ) * 1000 +
|
||||
( szDate[ 1 ] - '0' ) * 100 +
|
||||
( szDate[ 2 ] - '0' ) * 10 +
|
||||
( szDate[ 3 ] - '0' ) ) -1900;
|
||||
tmTime.tm_year = iYear - 1900;
|
||||
tmTime.tm_mon = iMonth - 1;
|
||||
tmTime.tm_mday = iDay;
|
||||
}
|
||||
else if( HB_ISDATETIME( 1 ) )
|
||||
{
|
||||
int iYear, iMonth, iDay, iHour, iMinute, iSecond, iMSec;
|
||||
|
||||
tmTime.tm_mon = (
|
||||
( szDate[ 4 ] - '0' ) * 10 +
|
||||
( szDate[ 5 ] - '0' ) ) - 1;
|
||||
hb_timeStampUnpack( hb_partd( 1 ), &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSecond, &iMSec );
|
||||
|
||||
tmTime.tm_mday =
|
||||
( szDate[ 6 ] - '0' ) * 10 +
|
||||
( szDate[ 7 ] - '0' );
|
||||
|
||||
tmTime.tm_hour = ulHour / 3600;
|
||||
tmTime.tm_min = ( ulHour % 3600 ) / 60;
|
||||
tmTime.tm_sec = ( ulHour % 60 );
|
||||
tmTime.tm_year = iYear - 1900;
|
||||
tmTime.tm_mon = iMonth - 1;
|
||||
tmTime.tm_mday = iDay;
|
||||
tmTime.tm_hour = iHour;
|
||||
tmTime.tm_min = iMinute;
|
||||
tmTime.tm_sec = iSecond;
|
||||
}
|
||||
|
||||
nLen = strftime( szRet, 64, "%a, %d %b %Y %H:%M:%S %z", &tmTime );
|
||||
/* For compatibility */
|
||||
if( HB_ISNUM( 2 ) )
|
||||
{
|
||||
ULONG ulHour = hb_parnl( 2 );
|
||||
|
||||
tmTime.tm_hour = ulHour / 3600;
|
||||
tmTime.tm_min = ( ulHour % 3600 ) / 60;
|
||||
tmTime.tm_sec = ulHour % 60;
|
||||
}
|
||||
|
||||
strftime( szRet, sizeof( szRet ), "%a, %d %b %Y %H:%M:%S %z", &tmTime );
|
||||
|
||||
#endif
|
||||
|
||||
if( nLen < 64 )
|
||||
szRet = ( char * ) hb_xrealloc( szRet, nLen + 1 );
|
||||
|
||||
hb_retclen_buffer( szRet, nLen );
|
||||
hb_retc( szRet );
|
||||
}
|
||||
|
||||
/** Detects the mimetype of a given file */
|
||||
|
||||
@@ -142,23 +142,21 @@ HB_FUNC( WIN_SYSREFRESH )
|
||||
|
||||
HB_FUNC( HB_UTCOFFSET )
|
||||
{
|
||||
char * szRet = ( char * ) hb_xgrab( 6 );
|
||||
int nLen;
|
||||
char szRet[ 6 ];
|
||||
|
||||
#if defined( HB_OS_WIN )
|
||||
{
|
||||
TIME_ZONE_INFORMATION tzInfo;
|
||||
DWORD retval = GetTimeZoneInformation( &tzInfo );
|
||||
|
||||
if( GetTimeZoneInformation( &tzInfo ) == TIME_ZONE_ID_INVALID )
|
||||
if( retval == TIME_ZONE_ID_INVALID )
|
||||
tzInfo.Bias = 0;
|
||||
else
|
||||
tzInfo.Bias = -tzInfo.Bias;
|
||||
tzInfo.Bias = -( tzInfo.Bias + ( retval == TIME_ZONE_ID_STANDARD ? tzInfo.StandardBias : tzInfo.DaylightBias ) );
|
||||
|
||||
hb_snprintf( szRet, 6, "%+03d%02d",
|
||||
( int )( tzInfo.Bias / 60 ),
|
||||
( int )( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
|
||||
|
||||
nLen = strlen( szRet );
|
||||
hb_snprintf( szRet, sizeof( szRet ), "%+03d%02d",
|
||||
( int ) ( tzInfo.Bias / 60 ),
|
||||
( int ) ( tzInfo.Bias % 60 > 0 ? - tzInfo.Bias % 60 : tzInfo.Bias % 60 ) );
|
||||
}
|
||||
#else
|
||||
{
|
||||
@@ -171,12 +169,9 @@ HB_FUNC( HB_UTCOFFSET )
|
||||
# else
|
||||
tmTime = *localtime( ¤t );
|
||||
# endif
|
||||
nLen = strftime( szRet, 6, "%z", &tmTime );
|
||||
strftime( szRet, sizeof( szRet ), "%z", &tmTime );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( nLen < 6 )
|
||||
szRet = ( char * ) hb_xrealloc( szRet, nLen + 1 );
|
||||
|
||||
hb_retclen_buffer( szRet, nLen );
|
||||
hb_retc( szRet );
|
||||
}
|
||||
|
||||
@@ -255,9 +255,9 @@ void hb_dateDecode( long lJulian, int *piYear, int *piMonth, int *piDay )
|
||||
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 ) );
|
||||
*piYear = ( int ) ( X + U + ( W - 49 ) * 100 );
|
||||
*piMonth = ( int ) ( V + 2 - ( U * 12 ) );
|
||||
*piDay = ( int ) ( lJulian - ( 2447 * V / 80 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user