Code: Select all
; Size and time formatting functions
; (c) KingLestat, 2007
;
Procedure.s SizeFormat ( Value.q )
Protected work.d
Protected temp.s, dot.s, front.s
Protected ends.s = " bytes"
Protected i.l, j.l, k.l, l.l
work.d = Value
If work > ( 1048576 * 1024 )
work / 1048576
work / 1024
ends = " GB"
ElseIf work > 1048576
work / 1048576
ends = " MB"
ElseIf work > 1024
work / 1024
ends = " KB"
EndIf
temp = StrD ( work, 2 )
k = Len ( temp )
j = k - 3
If Right ( temp, 1 ) = "0"
k - 1
If Mid ( temp, k, 1 ) = "0"
k - 2
j = 0
EndIf
temp = Left ( temp, k )
EndIf
If j
dot = Right ( temp, k - j )
front = Left ( temp, j )
Else
dot = ""
front = temp
EndIf
If j > 3
l = ( ( ( j - 2 ) * 10 ) / 3 )
front = Space ( l )
k = l
i = 0
While ( j > 0 )
j - 1
k - 1
i + 1
PokeC ( @front + k, PeekC ( @temp + j ) )
If i % 3 = 0 And j > 1
k - 1
PokeC ( @front + k, 44 )
EndIf
Wend
EndIf
ProcedureReturn LTrim ( front + dot + ends )
EndProcedure
Procedure.s TimeFormat ( Value.l )
Protected temp.l
Protected days.s = ""
Protected hours.s = ""
Protected minutes.s = ""
Protected seconds.s = ""
Protected secs.f
Protected result.s = ""
If Value > 86400000
temp = Value / 86400000
Value % 86400000
If temp > 1
days = Str ( temp ) + " days"
Else
days = "1 day"
EndIf
EndIf
If Value > 3600000
temp = Value / 3600000
Value % 3600000
If temp > 1
hours = Str ( temp ) + " hours"
Else
days = "1 hour"
EndIf
EndIf
If Value > 60000
temp = Value / 60000
Value % 60000
If temp > 1
minutes = Str ( temp ) + " minutes"
Else
minutes = "1 minute"
EndIf
EndIf
secs = Value / 1000
seconds = StrF ( secs, 2 )
temp = Len ( seconds )
While ( Right ( seconds, 1 ) = "0" Or Right ( seconds, 1 ) = "." )
temp - 1
seconds = Left ( seconds, temp )
Wend
If days > ""
result = days
EndIf
If hours > ""
If result > ""
result + ", " + hours
Else
result = hours
EndIf
EndIf
If minutes > ""
If result > ""
result + ", " + minutes
Else
result = minutes
EndIf
EndIf
If seconds > ""
If result > ""
result + ", " + seconds
Else
result = seconds
EndIf
result + " seconds"
EndIf
ProcedureReturn result
EndProcedure
Debug SizeFormat ( 128 )
Debug SizeFormat ( 1280 )
Debug SizeFormat ( 12800 )
Debug SizeFormat ( 128000 )
Debug SizeFormat ( 1280000 )
Debug SizeFormat ( 12800000 )
Debug SizeFormat ( 128000000 )
Debug SizeFormat ( 1280000000 )
Debug SizeFormat ( 12800000000 )
Debug SizeFormat ( 128000000000 )
Debug SizeFormat ( 1280000000000 )
Debug SizeFormat ( 12800000000000 )
Debug SizeFormat ( 128000000000000 )
Debug SizeFormat ( 1280000000000000 )
Debug SizeFormat ( 12800000000000000 )
Debug SizeFormat ( 128000000000000000 )
Debug TimeFormat ( 120 )
Debug TimeFormat ( 12000 )
Debug TimeFormat ( 51214700 )
Debug TimeFormat ( 151214700 )