Hallo,
I've written a program to create reports out of log files.
On german logs it works fine. On american logs it won't because of the date functions.
e.g. I try to read the string below and convert it to a date
german: time 29.04.2003 14:56:47
american:
time 5/6/2003 4:29:48 PM
The date function do not support AM/PM and I have problems with the missing leading zeros.
Is there a library for american style dates ?
Michael
date functions missing pm and am
Re: date functions missing pm and am
> e.g. I try to read the string below and convert it to a date
> german: time 29.04.2003 14:56:47
Are you saying that the log files you're reading has the dates in the format
shown above, and you'd like to display them as American dates?
> german: time 29.04.2003 14:56:47
Are you saying that the log files you're reading has the dates in the format
shown above, and you'd like to display them as American dates?
Thanks,
done.
extract:
This works for me, cause the US version will always run on a US server, the EMEA version on a german server.
scanrec reads logfiles with a fixed format, that I can't change and fills a linked list.
This List us used to create a table and then a HTML file.
MyFormatDate is used to convert the date back to a string.
Michael
P.S:
I didn't post the complete code, cause without the server and the log files and the other html and idc/htx scripts around it, it doesn't make sense.
Since the server is company internal, I can't post a link.
done.
extract:
Code: Select all
;Europe=0
;Americas=1
#region=0
#am=0
#pm=3600*12
CompilerIf #region=0
datimask="%dd.%mm.%yyyy %hh:%ii:%ss"
region="EMEA"
CompilerElse
datimask="%mm/%dd/%yyyy %hh:%ii:%ss"
region="US"
CompilerEndIf
Procedure.s MyFormatDate(datim.l)
temp.s
result.s
CompilerIf #region=0
result=FormatDate(datimask,datim)
CompilerEndIf
CompilerIf #region=1
result=FormatDate(datimask,datim)
temp=Left(StringField(result,2," "),2)
If Val(temp)>12
datim-#pm
result=FormatDate(datimask,datim)+" PM"
Else
result+" AM"
EndIf
CompilerEndIf
ProcedureReturn result
EndProcedure
Procedure scanrec(orec.s)
line.s
field.s
value.s
datim.s
ampm.s
info.s
AddElement(alrec())
If ReadFile(0,orec)
Repeat
line=ReadString()
field=Trim(ReplaceString(StringField(line,1,":"),Chr(9)," ",1))
Select field
Case "Priority"
alrec()\priority=Trim(ReplaceString(StringField(line,2,":"),Chr(9)," ",1))
Case "Message"
CompilerIf #region=0
datim=StringField(line,2," ")+" "+Left(StringField(line,3," "),8)
alrec()\timestamp=ParseDate(datimask,datim)
alrec()\info=StringField(line,2,"]")
alrec()\message=StringField(line,12," ")
If alrec()\message="the"
alrec()\message="EICAR.test.virus"
EndIf
CompilerEndIf
CompilerIf #region=1
datim=StringField(line,2," ")+" "+Left(StringField(line,3," "),8)
ampm=Left(StringField(line,4," "),2)
alrec()\timestamp=ParseDate(datimask,datim)
If ampm="PM"
alrec()\timestamp+#pm
EndIf
alrec()\info=StringField(line,2,"]")
alrec()\message=StringField(line,14," ")
If alrec()\message="the"
alrec()\message="EICAR.test.virus"
EndIf
CompilerEndIf
Case "From"
alrec()\from=StringField(Trim(ReplaceString(StringField(line,2,":"),Chr(9)," ",1)),1,".")
EndSelect
Until Eof(0)<>0
CloseFile(0)
EndIf
EndProcedure
scanrec reads logfiles with a fixed format, that I can't change and fills a linked list.
This List us used to create a table and then a HTML file.
MyFormatDate is used to convert the date back to a string.
Michael
P.S:
I didn't post the complete code, cause without the server and the log files and the other html and idc/htx scripts around it, it doesn't make sense.
Since the server is company internal, I can't post a link.


