------=_NextPart_000_001F_01C4FBEF.FDE56000
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all!
The "Date and Time Function" request a week or so ago inspired me to =
update my function that I supplied. I wanted to see how closely I could =
emulate the date() function in PHP, and this is the result.
It's fully tested, 3.9x compliant (I don't own a compiler to test 4.x, =
but I think it would compile?), and works perfectly on my machine.
Current format codes supported:
Format Description (Example)
DAY =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
d Day of the month, 2 digits with leading zeros (01 - 31)
D A textual representation of a day, three letters (Sun - Sat)
j Day of the month without leading zeros (1 - 31)
l Lower-case 'L' - A full textual representation of the day of the =
week (Sunday - Saturday)
MONTH =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
F A full textual representation of a month (January - December)
m Numeric representation of a month, with leading zeros (01 - 12)
M A short textual representation of a month, three letters (Jan - =
Dec)
n Numeric representation of a month, without leading zeros (1 - 12)
YEAR =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
Y A full numeric representation of a year (2000 or 2001)
y A two digit representation of a year (00 or 01)
TIME =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
a Lowercase Ante meridiem and Post meridiem (am or pm)
A Uppercase Ante meridiem and Post meridiem (AM or PM)
g 12-hour format of an hour without leading zeros (1 - 12)
h 12-hour format of an hour with leading zeros (01 - 12)
i Minutes with leading zeros (00 - 59)
s Seconds, with leading zeros (00 - 59)
Currently format codes are opposite of PHP - preceed all format codes =
with a backslash and enter everything else as normal text
e.g. "/F /j, /Y, /g:/i /a" will outputs "March 10, 2001, 5:16 pm"
<MvCOMMENT>
| time_t_date(time_t, timezone, format) Use PHP date() format codes =
with a preceeding backslash (e.g. '/F /j, /Y, /g:/i /a' outputs 'March =
10, 2001, 5:16 pm')
</MvCOMMENT>
<MvFUNCTION name=3D"time_t_date" PARAMETERS=3D"cut,tz,format" =
STANDARDOUTPUTLEVEL=3D"compresswhitespace" =
ERROROUTPUTLEVEL=3D"syntax,expression,runtime">
<MvASSIGN name=3D"l.months" =
value=3D"January|February|March|April|May|June|Jul y|August|September|Octo=
ber|November|December">
<MvASSIGN NAME=3D"l.dayofweek" =
VALUE=3D"Sunday|Monday|Tuesday|Wednesday|Thursday| Friday|Saturday">
<MvASSIGN name=3D"l.hour" value=3D"{time_t_hour(l.cut,l.tz)}">
<MvASSIGN name=3D"l.ampm" value=3D"am">
<MvIF EXPR=3D"{l.hour GT 11}">
<MvASSIGN name=3D"l.ampm" value=3D"pm">
</MvIF>
<MvIF EXPR=3D"{l.hour GT 12}">
<MvASSIGN name=3D"l.hour" value=3D"{l.hour - 12}">
</MvIF>
<MvIF EXPR=3D"{l.hour LT 1}">
<MvASSIGN name=3D"l.hour" value=3D"12">
</MvIF>
<MvASSIGN NAME=3D"l.format" =
VALUE=3D"{glosub(glosub(glosub(glosub(glosub(glosu b(glosub(glosub(glosub(=
glosub(glosub(glosub(glosub(glosub(glosub(glosub(l .format,'/d',padl(time_=
t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',=
time_t_dayofweek(l.cut,l.tz)),0,3)),'/j',time_t_dayofmonth(l.cut, =
l.tz)),'/l',gettoken(l.dayofweek,'|',time_t_dayofweek(l.cut ,l.tz))),'/F',=
gettoken(l.months,'|',time_t_month(l.cut,l.tz))),'/m',padl(time_t_month(l=
.cut,l.tz),2,'0')),'/M',substring(gettoken(l.months,'|',time_t_month(l. cu=
t, =
l.tz)),0,3)),'/n',time_t_month(l.cut,l.tz)),'/Y',time_t_year(time_t,time_=
zone)),'/y',substring(time_t_year(time_t,time_zone),3,2)),'/a',l.ampm),'/=
A',toupper(l.ampm)),'/g',l.hour),'/h',padl(l.hour,2,'0')),'/i',padl(time_=
t_min(l.cut, l.tz),2,'0')),'/s',padl(time_t_min(l.cut, l.tz),2,'0'))}">
<MvFUNCRETURN VALUE=3D"{l.format}">
</MvFUNCTION>
It turned out to be only 106 bytes larger than my previous function, but =
the level of customization I think greatly out-weighs that.
Also, I haven't timed this, so I don't know how it performs compared to =
the old function. I'm sure it's a fraction slower though.
Finally, if the email servers eat it and destroy the code, you can =
download it in .txt format here: =
<A HREF ="http://www.winterboard.com/date_function.txt">http://www.winterboard.com/date_function.txt</A>
Sincerely,
- Tim Barkus
------=_NextPart_000_001F_01C4FBEF.FDE56000--
Comment