* bin/hb-func.sh
* bin/hb-mkdyn.bat
* bin/hb-mkdyn.sh
* bin/postinst.bat
* bin/postinst.cmd
* bin/postinst.sh
* contrib/examples/hbdoc/examples/core_es/array.txt
* contrib/examples/hbdoc/examples/core_es/binnum.txt
* contrib/examples/hbdoc/examples/core_es/browse.txt
* contrib/examples/hbdoc/examples/core_es/clipper.txt
* contrib/examples/hbdoc/examples/core_es/cmdline.txt
* contrib/examples/hbdoc/examples/core_es/codebloc.txt
* contrib/examples/hbdoc/examples/core_es/command.txt
* contrib/examples/hbdoc/examples/core_es/compiler.txt
* contrib/examples/hbdoc/examples/core_es/datetime.txt
* contrib/examples/hbdoc/examples/core_es/dbdelim.txt
* contrib/examples/hbdoc/examples/core_es/dbsdf.txt
* contrib/examples/hbdoc/examples/core_es/dbstrux.txt
* contrib/examples/hbdoc/examples/core_es/dir.txt
* contrib/examples/hbdoc/examples/core_es/dirstruc.txt
* contrib/examples/hbdoc/examples/core_es/diskspac.txt
* contrib/examples/hbdoc/examples/core_es/error.txt
* contrib/examples/hbdoc/examples/core_es/eval.txt
* contrib/examples/hbdoc/examples/core_es/file.txt
* contrib/examples/hbdoc/examples/core_es/garbage.txt
* contrib/examples/hbdoc/examples/core_es/harbext.txt
* contrib/examples/hbdoc/examples/core_es/hb_apiln.txt
* contrib/examples/hbdoc/examples/core_es/hb_set.txt
* contrib/examples/hbdoc/examples/core_es/hb_vm.txt
* contrib/examples/hbdoc/examples/core_es/howtobsd.txt
* contrib/examples/hbdoc/examples/core_es/hvm.txt
* contrib/examples/hbdoc/examples/core_es/idle.txt
* contrib/examples/hbdoc/examples/core_es/input.txt
* contrib/examples/hbdoc/examples/core_es/lang.txt
* contrib/examples/hbdoc/examples/core_es/license.txt
* contrib/examples/hbdoc/examples/core_es/macro.txt
* contrib/examples/hbdoc/examples/core_es/math.txt
* contrib/examples/hbdoc/examples/core_es/memo.txt
* contrib/examples/hbdoc/examples/core_es/memvar2.txt
* contrib/examples/hbdoc/examples/core_es/misc.txt
* contrib/examples/hbdoc/examples/core_es/nation.txt
* contrib/examples/hbdoc/examples/core_es/objfunc.txt
* contrib/examples/hbdoc/examples/core_es/pcode.txt
* contrib/examples/hbdoc/examples/core_es/pragma.txt
* contrib/examples/hbdoc/examples/core_es/rdd.txt
* contrib/examples/hbdoc/examples/core_es/readme.txt
* contrib/examples/hbdoc/examples/core_es/sayget.txt
* contrib/examples/hbdoc/examples/core_es/setmode.txt
* contrib/examples/hbdoc/examples/core_es/statics.txt
* contrib/examples/hbdoc/examples/core_es/strotype.txt
* contrib/examples/hbdoc/examples/core_es/subcodes.txt
* contrib/examples/hbdoc/examples/core_es/tbrowse.txt
* contrib/examples/hbdoc/examples/core_es/tclass.txt
* contrib/examples/hbdoc/examples/core_es/tgetlist.txt
* contrib/examples/hbdoc/examples/core_es/tlabel.txt
* contrib/examples/hbdoc/examples/core_es/tracing.txt
* contrib/examples/hbdoc/examples/core_es/treport.txt
* contrib/examples/hbdoc/examples/core_es/var.txt
* contrib/examples/hbdoc/examples/core_es/vm.txt
* contrib/examples/pp/hbppcore.c
* contrib/gtwvg/gtwvg.c
* contrib/gtwvg/wvgcore.c
* contrib/gtwvg/wvgcuig.c
* contrib/gtwvg/wvggui.c
* contrib/gtwvg/wvgutils.c
* contrib/gtwvg/wvgwin.c
* contrib/hbct/datetime.c
* contrib/hbct/pack.c
* contrib/hbct/video.c
* contrib/hbfbird/firebird.c
* contrib/hbfbird/tfirebrd.prg
* contrib/hbfimage/readme.txt
* contrib/hbgd/doc/hbgd.txt
* contrib/hbmisc/dates2.c
* contrib/hbmisc/doc/en/dates2.txt
* contrib/hbmisc/doc/en/ht_class.txt
* contrib/hbmisc/doc/en/ht_conv.txt
* contrib/hbmisc/doc/en/ht_dbf.txt
* contrib/hbmisc/doc/en/ht_doc.txt
* contrib/hbmisc/doc/en/ht_str.txt
* contrib/hbmysql/mysql.c
* contrib/hbnf/fttext.c
* contrib/hbodbc/odbc.c
* contrib/hbpgsql/postgres.c
* contrib/hbpgsql/tpostgre.prg
* contrib/hbsqlit3/hbsqlit3.c
* contrib/hbsqlit3/hbsqlit3.ch
* contrib/hbsqlit3/tests/blob.prg
* contrib/hbsqlit3/tests/metadata.prg
* contrib/hbsqlit3/tests/pack.prg
* contrib/hbsqlit3/tests/sqlite3_test.prg
* contrib/hbtip/utils.c
* contrib/hbwin/win_prn1.c
* contrib/hbwin/win_tprn.prg
* contrib/rddads/doc/en/adsfuncs.txt
* doc/class_tp.txt
* doc/en/array.txt
* doc/en/binnum.txt
* doc/en/browse.txt
* doc/en/command.txt
* doc/en/datetime.txt
* doc/en/dbdelim.txt
* doc/en/dbsdf.txt
* doc/en/dbstrux.txt
* doc/en/dir.txt
* doc/en/diskspac.txt
* doc/en/error.txt
* doc/en/eval.txt
* doc/en/file.txt
* doc/en/hb_api.txt
* doc/en/hb_apier.txt
* doc/en/hb_apifs.txt
* doc/en/hb_apigt.txt
* doc/en/hb_apiit.txt
* doc/en/hb_apiln.txt
* doc/en/hb_apird.txt
* doc/en/hb_compa.txt
* doc/en/hb_date.txt
* doc/en/hb_macro.txt
* doc/en/hb_set.txt
* doc/en/hb_vm.txt
* doc/en/hvm.txt
* doc/en/input.txt
* doc/en/lang.txt
* doc/en/math.txt
* doc/en/memo.txt
* doc/en/menu.txt
* doc/en/misc.txt
* doc/en/nation.txt
* doc/en/objfunc.txt
* doc/en/rdd.txt
* doc/en/rdddb.txt
* doc/en/rddmisc.txt
* doc/en/rddord.txt
* doc/en/set.txt
* doc/en/setmode.txt
* doc/en/string.txt
* doc/en/tclass.txt
* doc/en/terminal.txt
* doc/en/tgetlist.txt
* doc/en/tlabel.txt
* doc/en/treport.txt
* doc/en/var.txt
* doc/hdr_tpl.txt
* harbour-wce-spec
* harbour-win-spec
* harbour.spec
* include/hbapigt.h
* include/hbclass.ch
* include/hboo.ch
* make_gnu.bat
* make_gnu.sh
* mpkg_deb.sh
* mpkg_rpm.sh
* mpkg_rpm_from_svn.sh
* mpkg_rpm_wce.sh
* mpkg_rpm_win.sh
* mpkg_tgz.sh
* mpkg_win.bat
* mpkg_win.nsi
* source/common/hbdate.c
* source/common/hbstr.c
* source/common/hbver.c
* source/compiler/cmdcheck.c
* source/compiler/hbmain.c
* source/debug/dbgtwin.prg
* source/debug/debugger.prg
* source/lang/msgpt.c
* source/lang/msgptiso.c
* source/rtl/accept.c
* source/rtl/alert.prg
* source/rtl/console.c
* source/rtl/dates.c
* source/rtl/dateshb.c
* source/rtl/errorapi.c
* source/rtl/filesys.c
* source/rtl/gete.c
* source/rtl/getsys.prg
* source/rtl/getsys53.prg
* source/rtl/gtapi.c
* source/rtl/gtcrs/hb-charmap.def
* source/rtl/gtdos/gtdos.c
* source/rtl/gtos2/gtos2.c
* source/rtl/gtwin/gtwin.c
* source/rtl/gtwvt/gtwvt.c
* source/rtl/gx.c
* source/rtl/idle.c
* source/rtl/inkey.c
* source/rtl/mouseapi.c
* source/rtl/natmsg.c
* source/rtl/natmsgu.c
* source/rtl/net.c
* source/rtl/objfunc.prg
* source/rtl/round.c
* source/rtl/setpos.c
* source/rtl/tclass.prg
* source/rtl/tgetlist.prg
* source/rtl/tobject.prg
* source/rtl/transfrm.c
* source/rtl/valtype.c
* source/rtl/xsavescr.c
* source/vm/arrays.c
* source/vm/classes.c
* source/vm/eval.c
* source/vm/extend.c
* source/vm/extrap.c
* source/vm/fm.c
* source/vm/hvm.c
* source/vm/itemapi.c
* source/vm/memvars.c
* source/vm/proc.c
* tests/bnchmark/bnch_win.bat
* tests/langmsg.prg
* tests/rto_tb.prg
* utils/hbmk2/hbmk2.prg
* utils/hbtest/make_c5x.bat
* Changed reference:
doc/license.txt -> COPYING.
One step to allow the reorganization of doc dir.
629 lines
18 KiB
C
629 lines
18 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* The Date API (C level)
|
|
*
|
|
* Copyright 1999 David G. Holm <dholm@jsd-llc.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 2009 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* hb_timeFormat()
|
|
* hb_timeUnformat()
|
|
* hb_timeStampFormat()
|
|
* hb_timeStampUnformat()
|
|
*
|
|
* See COPYING for licensing terms.
|
|
*
|
|
*/
|
|
|
|
#include "hbapi.h"
|
|
#include "hbdate.h"
|
|
#include "hbset.h"
|
|
|
|
char * hb_dateFormat( const char * szDate, char * szFormattedDate, const char * szDateFormat )
|
|
{
|
|
/*
|
|
* NOTE: szFormattedDate must point to a buffer of at least 11 bytes.
|
|
* szDateFormat must point to a buffer holding the date format to use.
|
|
*/
|
|
int format_count, digit_count, size;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateFormat(%s, %p, %s)", szDate, szFormattedDate, szDateFormat));
|
|
|
|
/*
|
|
* Determine the maximum size of the formatted date string
|
|
*/
|
|
size = strlen( szDateFormat );
|
|
if( size > 10 )
|
|
size = 10;
|
|
|
|
if( szDate && strlen( szDate ) == 8 ) /* A valid date is always 8 characters */
|
|
{
|
|
const char * szPtr;
|
|
int digit;
|
|
BOOL used_d, used_m, used_y;
|
|
|
|
format_count = 0;
|
|
used_d = used_m = used_y = FALSE;
|
|
szPtr = szDateFormat;
|
|
|
|
while( format_count < size )
|
|
{
|
|
digit = HB_TOUPPER( ( UCHAR ) *szPtr );
|
|
szPtr++;
|
|
digit_count = 1;
|
|
while( HB_TOUPPER( ( UCHAR ) *szPtr ) == digit && format_count < size )
|
|
{
|
|
szPtr++;
|
|
if( format_count + digit_count < size )
|
|
digit_count++;
|
|
}
|
|
switch( digit )
|
|
{
|
|
case 'D':
|
|
switch( digit_count )
|
|
{
|
|
case 4:
|
|
if( ! used_d && format_count < size )
|
|
{
|
|
/* szFormattedDate[ format_count++ ] = '0'; */
|
|
szFormattedDate[ format_count++ ] = szDate[ 6 ];
|
|
digit_count--;
|
|
}
|
|
case 3:
|
|
if( ! used_d && format_count < size )
|
|
{
|
|
/* szFormattedDate[ format_count++ ] = '0'; */
|
|
szFormattedDate[ format_count++ ] = szDate[ 6 ];
|
|
digit_count--;
|
|
}
|
|
case 2:
|
|
if( ! used_d && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 6 ];
|
|
digit_count--;
|
|
}
|
|
default:
|
|
if( ! used_d && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 7 ];
|
|
digit_count--;
|
|
}
|
|
while( digit_count-- > 0 && format_count < size )
|
|
szFormattedDate[ format_count++ ] = ( char ) digit;
|
|
}
|
|
used_d = TRUE;
|
|
break;
|
|
|
|
case 'M':
|
|
switch( digit_count )
|
|
{
|
|
case 4:
|
|
if( ! used_m && format_count < size )
|
|
{
|
|
/* szFormattedDate[ format_count++ ] = '0'; */
|
|
szFormattedDate[ format_count++ ] = szDate[ 4 ];
|
|
digit_count--;
|
|
}
|
|
case 3:
|
|
if( ! used_m && format_count < size )
|
|
{
|
|
/* szFormattedDate[ format_count++ ] = '0'; */
|
|
szFormattedDate[ format_count++ ] = szDate[ 4 ];
|
|
digit_count--;
|
|
}
|
|
case 2:
|
|
if( ! used_m && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 4 ];
|
|
digit_count--;
|
|
}
|
|
default:
|
|
if( ! used_m && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 5 ];
|
|
digit_count--;
|
|
}
|
|
while( digit_count-- > 0 && format_count < size )
|
|
szFormattedDate[ format_count++ ] = ( char ) digit;
|
|
}
|
|
used_m = TRUE;
|
|
break;
|
|
|
|
case 'Y':
|
|
switch( digit_count )
|
|
{
|
|
case 4:
|
|
if( ! used_y && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 0 ];
|
|
digit_count--;
|
|
}
|
|
|
|
case 3:
|
|
if( ! used_y && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 1 ];
|
|
digit_count--;
|
|
}
|
|
|
|
case 2:
|
|
if( ! used_y && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 2 ];
|
|
digit_count--;
|
|
}
|
|
|
|
default:
|
|
if( ! used_y && format_count < size )
|
|
{
|
|
szFormattedDate[ format_count++ ] = szDate[ 3 ];
|
|
digit_count--;
|
|
}
|
|
while( digit_count-- > 0 && format_count < size )
|
|
szFormattedDate[ format_count++ ] = ( char ) digit;
|
|
}
|
|
used_y = TRUE;
|
|
break;
|
|
|
|
default:
|
|
while( digit_count-- > 0 && format_count < size )
|
|
szFormattedDate[ format_count++ ] = ( char ) digit;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* Not a valid date string, so return a blank date with separators */
|
|
format_count = size; /* size is either 8 or 10 */
|
|
hb_strncpy( szFormattedDate, szDateFormat, size );
|
|
|
|
for( digit_count = 0; digit_count < size; digit_count++ )
|
|
{
|
|
switch( szFormattedDate[ digit_count ] )
|
|
{
|
|
case 'D':
|
|
case 'd':
|
|
case 'M':
|
|
case 'm':
|
|
case 'Y':
|
|
case 'y':
|
|
szFormattedDate[ digit_count ] = ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
szFormattedDate[ format_count ] = '\0';
|
|
|
|
return szFormattedDate;
|
|
}
|
|
|
|
long hb_dateUnformat( const char * szDate, const char * szDateFormat )
|
|
{
|
|
int d_value = 0, m_value = 0, y_value = 0;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_dateUnformat(%s, %s)", szDate, szDateFormat));
|
|
|
|
if( szDate )
|
|
{
|
|
int d_pos = 0, m_pos = 0, y_pos = 0;
|
|
int count, digit, non_digit, size;
|
|
|
|
if( ! szDateFormat )
|
|
szDateFormat = hb_setGetDateFormat();
|
|
size = strlen( szDateFormat );
|
|
|
|
for( count = 0; count < size; count++ )
|
|
{
|
|
switch( szDateFormat[ count ] )
|
|
{
|
|
case 'D':
|
|
case 'd':
|
|
if( d_pos == 0 )
|
|
{
|
|
if( m_pos == 0 && y_pos == 0 )
|
|
d_pos = 1;
|
|
else if( m_pos == 0 || y_pos == 0 )
|
|
d_pos = 2;
|
|
else
|
|
d_pos = 3;
|
|
}
|
|
break;
|
|
case 'M':
|
|
case 'm':
|
|
if( m_pos == 0 )
|
|
{
|
|
if( d_pos == 0 && y_pos == 0 )
|
|
m_pos = 1;
|
|
else if( d_pos == 0 || y_pos == 0 )
|
|
m_pos = 2;
|
|
else
|
|
m_pos = 3;
|
|
}
|
|
break;
|
|
case 'Y':
|
|
case 'y':
|
|
if( y_pos == 0 )
|
|
{
|
|
if( m_pos == 0 && d_pos == 0 )
|
|
y_pos = 1;
|
|
else if( m_pos == 0 || d_pos == 0 )
|
|
y_pos = 2;
|
|
else
|
|
y_pos = 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* If there are non-digits at the start of the date field,
|
|
they are not to be treated as date field separators */
|
|
non_digit = 1;
|
|
size = strlen( szDate );
|
|
for( count = 0; count < size; count++ )
|
|
{
|
|
digit = szDate[ count ];
|
|
if( HB_ISDIGIT( digit ) )
|
|
{
|
|
/* Process the digit for the current date field */
|
|
if( d_pos == 1 )
|
|
d_value = ( d_value * 10 ) + digit - '0';
|
|
else if( m_pos == 1 )
|
|
m_value = ( m_value * 10 ) + digit - '0';
|
|
else if( y_pos == 1 )
|
|
y_value = ( y_value * 10 ) + digit - '0';
|
|
/* Treat the next non-digit as a date field separator */
|
|
non_digit = 0;
|
|
}
|
|
else if( digit != ' ' )
|
|
{
|
|
/* Process the non-digit */
|
|
if( non_digit++ == 0 )
|
|
{
|
|
/* Only move to the next date field on the first
|
|
consecutive non-digit that is encountered */
|
|
d_pos--;
|
|
m_pos--;
|
|
y_pos--;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( y_value >= 0 && y_value < 100 )
|
|
{
|
|
count = hb_setGetEpoch();
|
|
digit = count / 100;
|
|
count %= 100;
|
|
|
|
if( y_value >= count )
|
|
y_value += ( digit * 100 );
|
|
else
|
|
y_value += ( ( digit * 100 ) + 100 );
|
|
}
|
|
}
|
|
|
|
return hb_dateEncode( y_value, m_value, d_value );
|
|
}
|
|
|
|
/* time modifiers:
|
|
* H - hour
|
|
* M - minutes
|
|
* S - seconds
|
|
* F - fractional part of seconds
|
|
* P - PM/AM marker
|
|
* maximal size of time pattern:
|
|
* 16 for "hh:mm:ss:ffff pp"
|
|
* always safe buffer size is 17 (+1 for 0)
|
|
*/
|
|
char * hb_timeFormat( char * szBuffer, const char * szTimeFormat, LONG lMilliSec )
|
|
{
|
|
char * szTimeBuffer;
|
|
int iHour, iMinutes, iSeconds, iMSec, iPM, i12;
|
|
int size, i, ch, count, value, digits, skip;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeFormat(%p, %s, %ld)", szBuffer, szTimeFormat, lMilliSec));
|
|
|
|
hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec );
|
|
szTimeBuffer = szBuffer;
|
|
|
|
size = hb_strnlen( szTimeFormat, 16 );
|
|
iPM = i12 = 0;
|
|
for( i = 0; i < size; ++i )
|
|
{
|
|
if( HB_TOUPPER( szTimeFormat[ i ] ) == 'P' )
|
|
{
|
|
if( iHour >= 12 )
|
|
{
|
|
iPM = 1;
|
|
iHour -= 12;
|
|
}
|
|
if( iHour == 0 )
|
|
iHour += 12;
|
|
if( iHour < 10 )
|
|
i12 = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
i = 0;
|
|
while( i < size )
|
|
{
|
|
count = -i;
|
|
ch = HB_TOUPPER( szTimeFormat[ i ] );
|
|
++i;
|
|
while( ch == HB_TOUPPER( szTimeFormat[ i ] ) && i < size )
|
|
++i;
|
|
count += i;
|
|
switch( ch )
|
|
{
|
|
case 'H':
|
|
value = iHour;
|
|
if( count == 2 && value >= 0 )
|
|
{
|
|
if( i12 )
|
|
{
|
|
*szTimeBuffer++ = ' ';
|
|
--count;
|
|
}
|
|
digits = count;
|
|
}
|
|
else
|
|
digits = 1;
|
|
iHour = -1;
|
|
break;
|
|
case 'M':
|
|
value = iMinutes;
|
|
iMinutes = -1;
|
|
digits = count > 2 ? 1 : count;
|
|
break;
|
|
case 'S':
|
|
value = iSeconds;
|
|
iSeconds = -1;
|
|
digits = count > 2 ? 1 : count;
|
|
break;
|
|
case 'F':
|
|
value = iMSec;
|
|
iMSec = -1;
|
|
digits = count > 4 ? 1 : count;
|
|
switch( digits )
|
|
{
|
|
case 4:
|
|
value *= 10;
|
|
break;
|
|
case 2:
|
|
value = ( value + 5 ) / 10;
|
|
break;
|
|
case 1:
|
|
value = ( value + 50 ) / 100;
|
|
break;
|
|
}
|
|
break;
|
|
case 'P':
|
|
if( iPM >= 0 )
|
|
{
|
|
*szTimeBuffer++ = iPM ? 'P' : 'A';
|
|
if( --count )
|
|
{
|
|
*szTimeBuffer++ = 'M';
|
|
--count;
|
|
}
|
|
iPM = -1;
|
|
}
|
|
default:
|
|
digits = value = 0;
|
|
}
|
|
if( digits && value >= 0 )
|
|
{
|
|
skip = digits;
|
|
count -= digits;
|
|
do
|
|
{
|
|
szTimeBuffer[ --digits ] = ( char ) ( '0' + value % 10 );
|
|
value /= 10;
|
|
}
|
|
while( digits );
|
|
szTimeBuffer += skip;
|
|
}
|
|
while( count-- )
|
|
*szTimeBuffer++ = ch;
|
|
}
|
|
|
|
*szTimeBuffer = '\0';
|
|
|
|
return szBuffer;
|
|
}
|
|
|
|
/*
|
|
* maximal size of time pattern:
|
|
* 16 for "hh:mm:ss:ffff pp"
|
|
* total maximal size of formatted timestamp value: 10 + 16 = 26
|
|
* always safe buffer size is: 27
|
|
*/
|
|
char * hb_timeStampFormat( char * szBuffer,
|
|
const char * szDateFormat, const char * szTimeFormat,
|
|
LONG lJulian, LONG lMilliSec )
|
|
{
|
|
char szDate[ 9 ], * szTimeBuffer;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampFormat(%p, %s, %s, %ld, %ld)", szBuffer, szDateFormat, szTimeFormat, lJulian, lMilliSec));
|
|
|
|
hb_dateDecStr( szDate, lJulian );
|
|
hb_dateFormat( szDate, szBuffer, szDateFormat );
|
|
szTimeBuffer = szBuffer + strlen( szBuffer );
|
|
*szTimeBuffer++ = ' ';
|
|
hb_timeFormat( szTimeBuffer, szTimeFormat, lMilliSec );
|
|
|
|
return szBuffer;
|
|
}
|
|
|
|
LONG hb_timeUnformat( const char * szTime, const char * szTimeFormat )
|
|
{
|
|
int iHour, iMinutes, iSeconds, iMSec, iPM;
|
|
int size, i, ch, count, digits, prec, * pValue;
|
|
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeUnformat(%s, %s)", szTime, szTimeFormat));
|
|
|
|
if( ! szTime )
|
|
return 0;
|
|
|
|
if( ! szTimeFormat )
|
|
szTimeFormat = hb_setGetTimeFormat();
|
|
|
|
size = hb_strnlen( szTime, hb_strnlen( szTimeFormat, 16 ) );
|
|
iHour = iMinutes = iSeconds = iMSec = iPM = -1;
|
|
prec = 0;
|
|
for( i = 0; i < size; ++i )
|
|
{
|
|
digits = i;
|
|
count = -i;
|
|
ch = HB_TOUPPER( szTimeFormat[ i ] );
|
|
++i;
|
|
while( ch == HB_TOUPPER( szTimeFormat[ i ] ) && i < size )
|
|
++i;
|
|
count += i;
|
|
switch( ch )
|
|
{
|
|
case 'H':
|
|
if( count == 2 )
|
|
{
|
|
if( szTime[ digits ] == ' ' )
|
|
++digits;
|
|
}
|
|
else if( count > 2 )
|
|
count = 1;
|
|
pValue = &iHour;
|
|
break;
|
|
case 'M':
|
|
if( count > 2 )
|
|
count = 1;
|
|
pValue = &iMinutes;
|
|
break;
|
|
case 'S':
|
|
if( count > 2 )
|
|
count = 1;
|
|
pValue = &iSeconds;
|
|
break;
|
|
case 'F':
|
|
if( count > 4 )
|
|
count = 1;
|
|
prec = count;
|
|
pValue = &iMSec;
|
|
break;
|
|
case 'P':
|
|
if( iPM < 0 )
|
|
iPM = ( szTime[ digits ] == 'P' || szTime[ digits ] == 'p' ) ?
|
|
1 : 0;
|
|
default:
|
|
pValue = NULL;
|
|
}
|
|
if( pValue && *pValue < 0 )
|
|
{
|
|
*pValue = 0;
|
|
while( count-- > 0 && HB_ISDIGIT( szTime[ digits ] ) )
|
|
{
|
|
*pValue = *pValue * 10 + ( szTime[ digits ] - '0' );
|
|
++digits;
|
|
}
|
|
}
|
|
}
|
|
if( iHour < 0 )
|
|
iHour = 0;
|
|
if( iMinutes < 0 )
|
|
iMinutes = 0;
|
|
if( iSeconds < 0 )
|
|
iSeconds = 0;
|
|
if( iMSec < 0 )
|
|
iMSec = 0;
|
|
else if( iMSec > 0 )
|
|
{
|
|
if( prec == 4 )
|
|
iMSec /= 10;
|
|
else while( prec++ < 3 )
|
|
iMSec *= 10;
|
|
}
|
|
if( iPM > 0 )
|
|
{
|
|
if( iHour == 0 )
|
|
iHour = 24; /* wrong time */
|
|
else if( iHour != 12 )
|
|
iHour += 12;
|
|
}
|
|
else if( iPM == 0 )
|
|
{
|
|
if( iHour == 0 )
|
|
iHour = 24; /* wrong time */
|
|
else if( iHour == 12 )
|
|
iHour = 0;
|
|
}
|
|
|
|
return hb_timeEncode( iHour, iMinutes, iSeconds, iMSec );
|
|
}
|
|
|
|
void hb_timeStampUnformat( const char * szDateTime,
|
|
const char * szDateFormat, const char * szTimeFormat,
|
|
LONG * plJulian, LONG * plMilliSec )
|
|
{
|
|
HB_TRACE(HB_TR_DEBUG, ("hb_timeStampUnformat(%s, %s, %s, %p, %p)", szDateTime, szDateFormat, szTimeFormat, plJulian, plMilliSec));
|
|
|
|
if( szDateTime )
|
|
{
|
|
int size;
|
|
|
|
if( ! szDateFormat )
|
|
szDateFormat = hb_setGetDateFormat();
|
|
*plJulian = hb_dateUnformat( szDateTime, szDateFormat );
|
|
size = hb_strnlen( szDateTime, hb_strnlen( szDateFormat, 10 ) );
|
|
while( szDateFormat[ size ] == ' ' )
|
|
++size;
|
|
*plMilliSec = hb_timeUnformat( szDateTime + size, szTimeFormat );
|
|
}
|
|
else
|
|
*plJulian = *plMilliSec = 0;
|
|
}
|