Convert Cascade's timestamp to MM-DD-YYYY???

Joel Trauger's Avatar

Joel Trauger

15 Jan, 2015 08:53 PM

I was looking at the <created-on> and <last-modified> entries of a page's xml and noticed that the values appeared to be in UTC.

I quickly plugged them into a UTC convert I had and they registered as dates FAR into the future. Think: 40,000 years in the future!

I need to be able to show the date a page was created on my website for a University News archive and this is stumping me.

Any ideas?

  1. 1 Posted by Ryan Griffith on 16 Jan, 2015 06:21 PM

    Ryan Griffith's Avatar

    Hi Joel,

    The unix timestamps should are timezone independent and should be relative to the system time that is configured on the server. If you go to the Administration -> Dashboard -> Information tab, you should see the system time within the first row. Can you verify the time is correct here?

    If the time is correct, you should be to simply use the Velocity Date Tool to output the date a page was created. Consider the example provided with the Date Tool documentation for a starting point.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Joel Trauger on 16 Jan, 2015 09:44 PM

    Joel Trauger's Avatar

    Yes, the correct time is showing for the correct time zone.

    I, however, am running into another problem with the DateTool in that it is not appearing to return anything. My xml is as follows:

    <system-index-block name="Alumni" type="folder" current-time="1421444457994">
        <system-page id="ea2fc562c61010594b962cfa516820b7">
            <name>Article-about-fish</name>
            <is-published>true</is-published>
            <last-published-on>1421440984168</last-published-on>
            <last-published-by>system</last-published-by>
            <title>Interesting Article About Graduate Fish</title>
            <display-name>Interesting Article About Graduate Fish</display-name>
            <path>/news/AlumniNews/articles/Article-about-fish</path>
            <site>www</site>
            <link>site://www/news/AlumniNews/articles/Article-about-fish</link>
            <created-by>traugej</created-by>
            <created-on>1421268206932</created-on>
            <last-modified-by>traugej</last-modified-by>
            <last-modified>1421353159679</last-modified>
            <system-data-structure definition-path="news article">
                <image type="file">
                    <content />
                    <path>/_files/imgs/headerimage/dadandtwins.jpg</path>
                    <link>site://www/_files/imgs/headerimage/dadandtwins.jpg</link>
                    <site>www</site>
                    <name>dadandtwins.jpg</name>
                    <display-name>Alumni dad and twin daughter students</display-name>
                    <title>Alumni dad and twin daughter students</title>
                    <keywords>alumni, student, twin, scholarship, legacy</keywords>
                    <description>Henderson graduate and his twin daughters, who are current students at HSU</description>
                </image>
                <heading>Interesting Article About Graduate Fish</heading>
                <body>
                    <p>body goes here...</p>
                </body>
                <tags>
                    <value>Art</value>
                    <value>Mathematics</value>
                </tags>
            </system-data-structure>
        </system-page>
    </system-index-block>
    

    The part of my format that grabs the date is here:

    #set ( $xmlroot = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block") )
    #set ( $xml = $_XPathTool.selectNodes($xmlroot, "system-page") )
    #foreach ( $linkgroup in $xml )
        #set ( $dateraw = $linkgroup.getChild("created-on").value )
        #set ( $date = $_DateTool.format("MM/dd/yyyy", $_DateTool.getDate($dateraw) ) )
        <p>The date this article was created was:  ${date}</p>
    #end
    

    Perhaps I have just missed something?

  3. 3 Posted by Ryan Griffith on 19 Jan, 2015 01:36 PM

    Ryan Griffith's Avatar

    Hi Joel,

    Your code looks correct to me and I was able to confirm a date is displayed in my local 7.12.4 instance. Here is the output from the XML and Velocity you provided:

    <p>The date this article was created was:  01/14/2015</p>
    

    What results are you seeing?

    Thanks!

  4. 4 Posted by Joel Trauger on 19 Jan, 2015 02:49 PM

    Joel Trauger's Avatar

    It appears the debugging output of my format was not outputting anything I wasn't even getting:

    <p>The date this article was created was:  </p>
    

    But now, when I insert the date into XML so I can access it with JavaScript, it properly inserts the date into the XML.

    Why would it not work last week but suddenly work today?

  5. 5 Posted by Ryan Griffith on 19 Jan, 2015 03:17 PM

    Ryan Griffith's Avatar

    Definitely interesting, Joel, but I am glad to hear it appears to be working today.

    The Date Tool will default to the current date if the value passed into getDate is not a valid unix timestamp. So, I would expect to see either the correct date of 01/14/2015, or the current date (eg 01/19/2015).

    Please let me know if you have any questions.

    Thanks!

  6. 6 Posted by Joel Trauger on 19 Jan, 2015 04:47 PM

    Joel Trauger's Avatar

    Well I'm using the same code in a different format and the $_DateTool.format function isn't returning anything. It's as if the #set statement isn't doing anything:

    #set ( $link = $_XPathTool.selectSingleNode($linkgroup, "link").value )
    #set ( $dateraw = $linkgroup.getChild("created-on").value )
    #set ( $date = $_DateTool.format("MM/dd/yyyy",  $_DateTool.getDate($dateraw) ) )
    
    ## some other code here
    
    <p>
        <em><a href="${link}">READ MORE...</a><br />${date}
    </p>
    

    I literally copied and pasted the code into a format that uses the same index block as the first.

    My output:

    <p>
        <em>
            <a href="site://www/news/AlumniNews/articles/Article-about-fish">READ MORE...</a>
            <br />${date}
        </em>
    </p>
    
  7. 7 Posted by Joel Trauger on 19 Jan, 2015 04:53 PM

    Joel Trauger's Avatar

    Nevermind I found the error. It all works now.

  8. 8 Posted by Ryan Griffith on 19 Jan, 2015 05:11 PM

    Ryan Griffith's Avatar

    Thank you for following up, Joel. I am glad to hear you were able to track down the issue.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  9. Ryan Griffith closed this discussion on 19 Jan, 2015 05:11 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac