Created
October 18, 2012 18:52
-
-
Save mhulse/3914071 to your computer and use it in GitHub Desktop.
Caché DTI ContentPublisher: v7.7.3; CSP method: ODBC timestamp to W3C date for use with HTML5 <time> tag & RG publish date logic...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<csp:comment> | |
/// Converts an ODBC timestamp to W3C date for use with HTML5 <time> tag. | |
/// | |
/// @param ODBC formatted timestamp. Example: 2010-10-25 01:08:21.512. Required. | |
/// @see http://bit.ly/fj8ZI1 | |
/// @see http://rgne.ws/QuTBrv | |
/// @see http://rgne.ws/S6kSSE | |
/// @see http://rgne.ws/Rh67IW | |
/// @return Valid rfc3339 formatted date. Example: YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00). | |
</csp:comment> | |
<script language="cache" method="w3cDate" arguments='ts:%TimeStamp=""' returntype="%String" procedureblock="1"> | |
quit $case(ts?4N2(1"-"2N)1" "2N2(1":"2N).1(1"."1.6N), 1:$replace($zdatetime($zdatetimeh(ts, 3), 3, 5), "/", "-"), :"") | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[ new ts set ts = ##class(csp.rg.assets.methods.story).pubDate(gStory) ]# | |
<csp:if condition=($length(ts))> | |
<p class="pub1">Published: <time pubdate datetime="#(##class(csp.rg.assets.methods.datetime).w3cDate(ts))#"><custom:rg:apdatetime timestamp="#(ts)#" /></time></p> | |
</csp:if> | |
#[ kill ts ]# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment> | |
<script language="cache" method="runDate" arguments='cmsStory:dt.cms.schema.CMSStory=-1' returntype="%String" procedureblock="1"> | |
set return = "" | |
try { | |
set cmsStoryId = cmsStory.%Id() | |
&sql( | |
SELECT runDate INTO :return | |
FROM dbo.adDbPageInfo api, dbo.storyPageElements spe, dbo.story sty, dt_cms_schema.CMSStory cms | |
WHERE api.logicalPageId = spe.logicalPagesId | |
AND sty.storyId = spe.storyId | |
AND story->storyid = sty.storyid | |
AND cms.id = :cmsStoryId | |
) | |
} catch(e) { | |
; What to log and where? | |
} | |
quit return | |
</script> | |
<csp:comment> | |
<csp:object name="gStory" classname="dt.cms.schema.CMSStory" objid="26035312"> | |
#(..rundate(gStory))# | |
<br> | |
</csp:comment> | |
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment> | |
<script language="cache" method="cmsPubTracking" arguments='cmsStory:dt.cms.schema.CMSStory=-1, latest:%Integer=0' returntype="%TimeStamp" procedureblock="1"> | |
set return = "" | |
; By default, get the oldest entry: | |
set order = $case(latest, 1:"DESC", :"ASC") | |
try { | |
; See Roberto's and Sungung's replies: | |
; https://groups.google.com/d/topic/intersystems-public-cache/yKft-NK826I/discussion | |
; https://groups.google.com/d/topic/intersystems-public-cache/DH1fQOzwPiM/discussion | |
set sql = "SELECT StartDate FROM dt_cms_schema.CMSStoryPubTracking WHERE CMSStory = ? ORDER BY StartDate " _ order | |
set (sc1, sc2, sc3) = -1 | |
set rs = ##class(%ResultSet).%New() | |
set sc1 = rs.Prepare(sql) | |
if ($$$ISOK(sc1)) { | |
set sc2 = rs.Execute(cmsStory.%Id()) | |
if ($$$ISOK(sc2)) { | |
do rs.%Next(.sc3) | |
set:($$$ISOK(sc3)) return = rs.GetData(1) | |
} | |
} | |
} catch(e) { | |
; What to log and where? | |
} | |
quit return | |
</script> | |
<csp:comment> | |
<csp:object name="gStory" classname="dt.cms.schema.CMSStory" objid="27846880"> | |
#(..cmsPubTracking(gStory))# | |
<br> | |
#(##class(csp.rg.assets.methods.datetime).timesince(##class(csp.rg.assets.methods.datetime).cmsPubTracking(gStory)))# ago. | |
</csp:comment> | |
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment> | |
<csp:comment> | |
/// Gets a story's publish date where RunDate trumps PubTracking trumps PublishedToWebDate trumps LastModified... Weeeee!!!! | |
/// | |
/// @dependency rundDate() | |
/// @dependency cmsPubTracking() | |
/// @param Valid CMSStory object. | |
/// @regurn Timestamp. | |
</csp:comment> | |
<script language="cache" method="pubDate" arguments="cmsStory:dt.cms.schema.CMSStory=-1" returntype="%TimeStamp" procedureblock="1"> | |
; Alternative ways to show a published date: | |
; ##class(dt.cms.support.Rules).formatDateTime(ts, 9, 4, 0) = Wednesday, Oct 17, 2012 12:58PM | |
; <dti:story field="lastModTime" dateFormat="12" />, <dti:story field="lastModTime" dateFormat="5" timeFormat="4" /> | |
set return = "" | |
if ($isobject(cmsStory)) { | |
/** | |
* Get the various story dates. | |
*/ | |
set return = ..runDate(cmsStory) // The rundate is from a DT publication Plan. | |
if ( ' $length(return)) { | |
set return = ..cmsPubTracking(cmsStory) // This table is used to track publishing/unpublishing of a web story and the cooresponding sections. | |
if ( ' $length(return)) { | |
set return = cmsStory.publishedToWebDate // Date & time story was published onto the live web (IIRC, this updates when section modifed and story "moves" via Lightning). | |
if ( ' $length(return)) { | |
set return = cmsStory.getLastModified() // Gets a story's last mod time; uses created time if all else fails. | |
if ( ' $length(return)) { | |
set return = $zdatetime($horolog, 3) // Last resort: Current date and time (this should'nt happen). | |
} | |
} | |
} | |
} | |
} | |
quit return | |
</script> | |
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment> |
Correction to my above comment.
HTML:
<p class="pub1">Published: <time pubdate datetime="2012-10-18T00:00:00-07:00">12:00 a.m., Oct. 18</time></p>
There was a logic error in w3cDate
method; I had the date set to output MM-DD-YYYY
when it should be YYYY-MM-DD
.
Another example (getting today's date):
#($zdate($horolog, 12))#, #($piece($zdate($horolog, 9), ","))#, #($piece($zdate($horolog, 3), "-"))#
... which returns:
Sunday, February 3, 2013
Using my w3cDate()
function:
<time datetime="#(##class(csp.rg.assets.methods.datetime).w3cDate($zdatetime($horolog, 3)))#">#($zdate($horolog, 12))#, #($piece($zdate($horolog, 9), ","))#, #($piece($zdate($horolog, 3), "-"))#</time>
... which returns:
<time datetime="2013-02-03T12:49:03-08:00">Sunday, February 3, 2013</time>
Enjoy!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What people see:
HTML:
Note:
I'm using my
<custom:rg:apdatetime ... />
RULE to output an AP style date/time.