Announcement

Collapse
No announcement yet.

Free Date and Time Function using PHP "date()" style formatting. (found and fixed a bug)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Free Date and Time Function using PHP "date()" style formatting. (found and fixed a bug)



    I just wanted to thank everyone for their compliments, and offer an apology.

    There was a small error in the function with the 'y' and 'Y' codes.

    Both have been fixed and here is the updated function:

    <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="time_t_date" PARAMETERS="cut,tz,format"
    STANDARDOUTPUTLEVEL="compresswhitespace"
    ERROROUTPUTLEVEL="syntax,expression,runtime">
    <MvASSIGN name="l.months"
    value="January|February|March|April|May|June|July| August|September|October|November|December">
    <MvASSIGN NAME="l.dayofweek"
    VALUE="Sunday|Monday|Tuesday|Wednesday|Thursday|Fr iday|Saturday">
    <MvASSIGN name="l.hour" value="{time_t_hour(l.cut,l.tz)}">
    <MvASSIGN name="l.ampm" value="am">
    <MvIF EXPR="{l.hour GT 11}">
    <MvASSIGN name="l.ampm" value="pm">
    </MvIF>
    <MvIF EXPR="{l.hour GT 12}">
    <MvASSIGN name="l.hour" value="{l.hour - 12}">
    </MvIF>
    <MvIF EXPR="{l.hour LT 1}">
    <MvASSIGN name="l.hour" value="12">
    </MvIF>
    <MvASSIGN NAME="l.format"
    VALUE="{glosub(glosub(glosub(glosub(glosub(glosub( glosub(glosub(glosub(glosub(glosub(glosub(glosub(g losub(glosub(glosub(l.format,'/d',padl(time_t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',time_t_dayof week(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. cut,
    l.tz)),0,3)),'/n',time_t_month(l.cut,l.tz)),'/Y',time_t_year(l.cut,l.tz)),'/y',substring(time_t_year(l.cut,l.tz),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="{l.format}">
    </MvFUNCTION>

    I've also updated the .txt file I have hosted at:
    <A HREF ="http://www.winterboard.com/date_function.txt">http://www.winterboard.com/date_function.txt</A>

    Again, my apologies to anyone that may have been using this.

    Sincerely,
    - Tim Barkus

    ----- Original Message -----
    From: "Nerd Boy Help Desk" <[email protected]>
    To: "Tim Barkus" <[email protected]>; "Miva Users List"
    <[email protected]>
    Sent: Sunday, January 16, 2005 9:52 PM
    Subject: Re: [meu] Free Date and Time Function using PHP "date()" style
    formatting.


    > Dear Tim,
    >
    > I was bored and tired of working, so I tried to compile your
    > function....it compiled with no errors.
    >
    > Compiled size by itself is 3,341 bytes. Not that it means anything.
    >
    > Thought you might want to know it compiled OK.
    >
    > OK....play time over.....back to work.
    >
    > Thank you,
    >
    > Nerd Boy
    > 1-573-292-1136
    > <A HREF ="http://www.nerdboyinc.com">http://www.nerdboyinc.com</A>
    > <A HREF ="http://www.nerdboyproductions.com">http://www.nerdboyproductions.com</A>
    > <A HREF ="http://www.nbicentral.com">http://www.nbicentral.com</A>
    > <A HREF ="http://www.asmallurl.com">http://www.asmallurl.com</A>
    > <A HREF ="http://www.yourlottosite.com">http://www.yourlottosite.com</A>
    >
    > For Customer Service and Support:
    > http://suppert.nerdboyinc.com
    >
    > Follow The Nerd Boy
    > Owner/ Driver Legends Car #99
    > <A HREF ="http://www.nbiracing.com">http://www.nbiracing.com</A>
    >
    > ----- Original Message -----
    > From: "Tim Barkus" <[email protected]>
    > To: "Miva Users List" <[email protected]>
    > Sent: Sunday, January 16, 2005 4:22 PM
    > Subject: [meu] Free Date and Time Function using PHP "date()" style
    > formatting.
    >
    >
    > 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 ================================================== =========
    > 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 ================================================== =======
    > 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 ================================================== ========
    > Y A full numeric representation of a year (2000 or 2001)
    > y A two digit representation of a year (00 or 01)
    >
    > TIME ================================================== ========
    > 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="time_t_date" PARAMETERS="cut,tz,format"
    > STANDARDOUTPUTLEVEL="compresswhitespace"
    > ERROROUTPUTLEVEL="syntax,expression,runtime">
    > <MvASSIGN name="l.months"
    > value="January|February|March|April|May|June|July| August|September|October|November|December">
    > <MvASSIGN NAME="l.dayofweek"
    > VALUE="Sunday|Monday|Tuesday|Wednesday|Thursday|Fr iday|Saturday">
    > <MvASSIGN name="l.hour" value="{time_t_hour(l.cut,l.tz)}">
    > <MvASSIGN name="l.ampm" value="am">
    > <MvIF EXPR="{l.hour GT 11}">
    > <MvASSIGN name="l.ampm" value="pm">
    > </MvIF>
    > <MvIF EXPR="{l.hour GT 12}">
    > <MvASSIGN name="l.hour" value="{l.hour - 12}">
    > </MvIF>
    > <MvIF EXPR="{l.hour LT 1}">
    > <MvASSIGN name="l.hour" value="12">
    > </MvIF>
    > <MvASSIGN NAME="l.format"
    > VALUE="{glosub(glosub(glosub(glosub(glosub(glosub( glosub(glosub(glosub(glosub(glosub(glosub(glosub(g losub(glosub(glosub(l.format,'/d',padl(time_t_dayofmonth(l.cut,l.tz),2,'0')),'/D',substring(gettoken(l.dayofweek,'|',time_t_dayof week(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. cut,
    > 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="{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
    >
Working...
X