How can I apply date formatting to Ghost's post.published_at property? - date

How can I format post.published_at in Ghost?
By default this returns the string:
Mon Nov 04 2013 13:29:46 GMT+0100 (CET)
Using format returns the same string.
{{ post.published_at format='dddd, MMMM Do YYYY' }}

If post.published_at is a javascript DateTime, then you'll need to invoke a helper to format it.
It looks like the standard helper for this in Ghost is {{date}}, so try {{date post.published_at}}.
Here's a link to the Ghost helpers script file, since this doesn't seem to be published in documentation anywhere: https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/index.js

When using the {{date}} helper, you can then pass in any format supported by the moment javascript date library.
This helper, and all the others, are documented at http://docs.ghost.org/themes

Related

How to get RFC1123 Date format for current date time using XSLT 2.0

I am trying to retrieve current date time in RFC1123 date format in XSLT.
has anybody tried this using XSL2.0?
I have seen code for converting various date times based on zone in XSLT2.0 and to format in specific date time format such yyyy/mm/dd or YYYY:MM:DDTHH:MM:SS.0Z, but couldnt find a way to format it to show like this
Tue, 09 Jul 2019 20:34:29 GMT
concat(date:add('1970-01-01T00:00:00',concat('PT',floor(dp:time-value() div 1000),'S')),':',dp:time-value() mod 1000)
This returns in GMT format like this 2019-07-09T21:01:26:547
How to format it for - Tue, 09 Jul 2019 20:34:29 GMT using XSLT2.0?
Use current-dateTime() to get the current date and time and then use format-dateTime to format it as needed, see the spec https://www.w3.org/TR/xslt20/#function-format-dateTime on details: a picture string
'[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]'
on my machine in German summer time gives
format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')
as
Wed, 10 July 12:01:13 GMT+02:00
This is meant as an example on the use of format-dateTime, I haven't checked the exact details of the RFC you cited to try to implement the exact requirements.
Thanks for quick reply, your solution worked using Altova XML Spy, but unfortunately it didnt worked for me in Datapower using XSLT2.0, Not sure what was wrong, may be some issue with DP firmware version.
just for other users to make this post more helpful. I tried below 2 options which didnt work for me, but might be useful for others.
using XSLT
<xsl:value-of select="java:java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC))"></xsl:value-of>
<xsl:value-of select="format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')"/>
So I used Gateway script to get same date format which I was looking for and stored in context variable using below
var dateNeeded = new Date()).toUTCString(); //Thu, 11 Jul 2019 21:08:12 GMT

Tibco Businessworks Date Format

I'm trying to format a date in Tibco Businessworks 6.2.2 in the following format:
06-AUG-2015 12:11 AM
I've found the picture string on several websites for xpath that, according to those who use them, will format the date like this. I've not been able to figure out how to only get the AUG instead of AUGUST without JUNE and JULY showing up as JUN and JUL.
Here is the xpath I'm using:
format-dateTime(current-dateTime(), '[D01]-[MNn, *-3]-[Y0001] [h01]:[m01] [PN]')
Here is the output I'm getting:
06-August-2015 12:11 AM
Any and all information is greatly appreciated.
Try this :
format-dateTime(current-dateTime(), '[D01]-[MN, *-3]-[Y0001] [h01]:[m01] [PN]')
Output :
15-DEC-2015 05:56 P.M.
ref : http://www.w3.org/TR/xslt20/#date-time-examples
In Tibco BW you can use substring on the final output - for the month'AUGUST' with index from 0 to 3. But this seems to be a work around.
A better approach is to write a common process of Date formtter with JavaCode activity from Java Palette. It doesn't and need any specific jar/lib import.
new SimpleDateFormat("yyyy-MMM-dd HH:mm a").format(new Date())
have you tried MMM in stead of MNn?
I used this function. (BW 5.12)
tib:format-dateTime('dd-MMM-yyyy hh:mm a', current-dateTime())
Out
06-Jul-2017 11:34 AM

How to shorten date in telescope app?

I am using the telescope app. Currently in my post title template I am using scheduledAt to show a date when an event will be. I would like to shorten the date to just Thu May 07 2015 but I don't really know how to go about doing this.
In Telescope, there's a helper named formatDate specifically designed for that purpose, just call it in your template like this :
{{formatDate scheduledAt "ddd MMMM DD YYYY"}}
Under the hood, it's using momentjs to display the date object.
http://momentjs.com/docs/#/displaying/

Formatting post's date value in DocPad

Currently if my post has date: 2013-06-16 in my post, and I do #document.date in the post layout I get "Sat Jun 15 2013 19:00:00 GMT-0500 (CDT)".
I would like to get different formats. Like 2013-06-16 for the pubdate HTML5 tag (or something similar).
Or Jun 15, 2013 for the human readable post date, etc.
How can I accomplish this? BTW my layouts are using the .html.coffee file extension. :)
Figured it out! This is my docpad.coffee file:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L4-L5
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L41-L43
And here's my post template:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/src/layouts/post.html.coffee#L7-L8
Of course I only linked the relevant parts of the code. Basically I learned and used Moment.js. :)
Although I love Moment.js, if you prefer a solution that does not require an additional plugin and you don't need to do too much with the date, you could use native JavaScript.
For example, if you would like to output your date in this great, human-readable format: Saturday, November 15, 2014, you can use the following native JavaScript method, passing in an optional locale:
date.toLocaleDateString()
And when you need just the year, e.g. 2014, you can use:
date.getFullYear()
Bear in mind, you will need getFullYear and not getYear due to the whole Y2K thing.
With all of the other native JavaScript date methods, you can make your own combinations, though if you're including multiple date formats, you may want to let Moment.js do the heavy lifting.

Converting a string timestamp to Date results in reset to UNIX epoch

I'm having some problems converting a string to a date object in google apps script.
My dates are in the following format, from a 3rd party API:
2013-01-17T17:34:50.507
I am attempting to convert this to a Date object:
return Date(stringDate);
And this is being returned:
Thu Jan 01 01:00:00 GMT+01:00 1970
Can someone tell me what i'm doing wrong, and how to resolve this issue ?
With moment.js, it is as easy as this to parse any of ISO 8601 format.
var date = Moment.moment("2013-01-17T17:34:50.507").toDate();
You can use moment.js to parse your arbitrary date string as well.
To use moment.js in GAS, you just need to add it in the script editor.
Open your script in GAS script editor and go to "Resources" then "Libraries...", then put this project key MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48 and click "Add". Choose the version from the dropdown, then click "Save". Now, you are ready to use moment.js in GAS.
moment.js can be used to parse date string, create formatted date string, and many other date manipulation. Thanks to the author!
You can find the moment.js documentation here.
It doesn't appear that the Date object knows how to handle that date. The date is in ISO 8601 format. Javascript can handle Dates if they are given timezone information.
You will have to do some testing, but if those dates given to you are in UTC time, then just add a Z to the end of the date string before you call new Date().
Edit: The Apps Script Date object can't seem to handle a timezone other than UTC when parsing a Date. I opened an issue for it.
It doesn't work in GScript, at least for me at the time I'm writing it.
This post serves a working alternative: How do I format this date string so that google scripts recognizes it?
As of now new Date() seems to work:
var dT = new Date("2013-01-17T17:34:50.507");
console.info("dT: %s or %d", dT, dT.getTime());
returns dT: Thu Jan 17 17:34:50 GMT+01:00 2013 or 1.358440490507E12 in Google Apps Script