WebGUI
      Click here to register.
      
irc://irc.freenode.net#webgui

iPhoneGuy: WebGUI is a pile of crap.
rizen: If WebGUI is such a pile of crap, why do you use it?
iPhoneGuy: Because it's the best pile of crap out there.

If this is what people who hate us are saying, imagine what people who love us will say. Come join us on IRC.

DateParse - A parsing and reformatting date/time

User: ebruni
Date: 12/22/2005 5:37 am
Views: 3227
Rating: 24    Rate [
|
]

Current version: (2005-12-22)

Introduction

This macro allows to parse a date/time string and to reformat it in a custom format.

I create this macro because I needed of showing the publication date of RSS article which are in format like this

11 Dec 2005 14:44:24 GMT

but  I needed of formatting it in dd/mm/aaaa hh:mm format. I solved problem with this macro

^DateParse("%d %b %Y %T %Z","%d/%m/%y %R",<tmpl_var pubDate>");

Usage.

As you see, you could use three parameters for this macro

  1. the parser string, used to parse correctly the date/time string
  2. the output format
  3. the date/time string to reformat

All these parameters are optionals and default values are

  1. %s (the date/time string is in epoch time format)
  2. user profile date/time preference
  3. current time in epoch time

So using it as ^DateParse(); return current time in your profile format.

The syntax of the format and parser strings can be found here.

This macro has been tested in 6.7.8 but should be worked also in 6.8.x.

You can see an working example here.

How to install.

To install it copy DateParse.pm into lib/WebGUI/Macro. Then open WebGUI.conf and append

    DateParse=> DateParse

at the end of the macro section. If, as an example, last line is

    u => u_companyUrl

replace this with

    u => u_companyUrl, \
    DateParse => DateParse

 



Replies

Re: DateParse - A parsing and reformatting date/time
User: chrisjscott
Date: 11/14/2006 2:49 pm
Rating: 7    Rate [
|
]
Status: Approved

FYI, it appears that this DateParse macro does not work with WebGUI v7 - attempts to use it result in the following error in /var/log/webgui.log:

Undefined subroutine &WebGUI::Macro::DateParse::process called at /data/WebGUI/lib/WebGUI/Macro.pm line 145.


PreviousBackNext