How to shorten date in telescope app? - date

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/

Related

Changing the Date Format the p-Calendar Transfers

I have a component, p-Calendar.
I had no trouble finding a way to receive the date I selected, and modify it.
<p-calendar
[showIcon]="true"
(onSelect)="onSelectMethod($event)"
[(ngModel)]="myDate"
[dataType]="date"
>
</p-calendar>
So basically when I hit a different date in the calendar, it does catch the date correctly. It will transfer this information:
"Thu Dec 08 2016 00:00:00 GMT-0500 (Eastern Standard Time)"
While I can see that all this detail is useful, I really just want my component to receive:
12/08/16.
Is there any simple way to do this, perhaps some inherent method that comes with the calendar, without manually doing string modifications in my code? I read the documentation and couldn't find the information I am looking for.
The onBlur method seems to be transferring the data in the way I want it to. Unfortunately onBlur only works when you type in the date manually, or when you're one date selection behind. It would be great to somehow call PrimeNG's onBlur method after you made a selection in the calendar drop-down.
I wouldn't particularly recommend this as it's a hacky solution, it is probably better to do transformations of the myDate as appropriate for display or other purposes.
If you really, really want to do this so that the myDate in your component only contains a short date without all that time and location information you can go ahead and separate out the model bindings to make it work like so:
template.html
<p-calendar [ngModel]="myDate"
(onSelect)="onSelectMethod($event)"
[dataType]="date">
</p-calendar>
component.ts
onSelectMethod(event) {
let d = new Date(Date.parse(event));
this.myDate = `${d.getMonth()+1}/${d.getDate()}/${d.getFullYear()}`;
}
Here's a functioning demo: http://plnkr.co/edit/IGRfXjtqIo0TEr2iDC06?p=preview
In case you were wondering about applying a pipe, you would do a straight [(ngModel)]="myDate" bind and, where you want to see the short date in the template do {{myDate | date: 'MM/dd/yy'}}

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 can I apply date formatting to Ghost's post.published_at property?

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

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.

Grails: how to parse date.toString() without making a custom formatter?

I have a Grails application that needs to parse Dates out of strings that were created with the date.toString() method.
My system's default date.toString() format is "Thu Apr 20 00:27:00 CEST 2006" so I know I can turn a Date into a string and then back into an object using Date.parse('EEE MMM dd HH:mm:ss z yyyy', new Date().toString()).
But that's lame! I shouldn't have to reverse engineer the system's default date format. Plus, I'm not sure under what circumstances the default date format can change, thus breaking that code.
Is there a way to parse a date.toString() back into a Date without using a hand-rolled formatter like that?
Thanks!
Update: I filed this Jira ticket to get such a feature added Groovy. Someone commented on the ticket that Java's date.toString() method is hard-coded to use EEE MMM dd HH:mm:ss z yyyy. That sucks for Java to be so inflexible, but it makes it easier for me to live with hard-coding the formatter!
There's a page over here showing how bad this is in Java (and hence in Groovy)
I agree that there should be a Date.parse method in Groovy which uses this default Date.toString() format.
Maybe it's worth adding a request for improvement over on the Groovy JIRA?
As a temporary workaround, you could add your parse method to the String metaClass in Bootstrap.groovy?
String.metaClass.parseToStringDate = { Date.parse( 'EEE MMM dd HH:mm:ss z yyyy', delegate ) }
Then you can do:
new Date().toString().parseToStringDate()
anywhere in the groovy portions of your grails app
I haven't worked with Grails and I know this is not the answer to your question, but as a workaround, couldn't you just save the format-string as a global variable?
if u use it to convert to json, maybe code below could help:
//bootstrap
JSON.registerObjectMarshaller(Date) {
return it?.format("yyyy-MM-dd HH:mm:ss")
}