Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when a timestamp is passed as string, it fails #25

Open
sfj2 opened this issue Jun 13, 2014 · 11 comments
Open

when a timestamp is passed as string, it fails #25

sfj2 opened this issue Jun 13, 2014 · 11 comments
Labels

Comments

@sfj2
Copy link

sfj2 commented Jun 13, 2014

the @intlDate only works if the timestamp is passed as a number, doesn't work if if it's a string, due to this it's almost impossible to use this, since when we have to pass some data to the helper, we can only do it as a string -

eg. -
{@intlDate timeZone="UTC" val=12344555555 /} - works

{@intlDate timeZone="UTC" val="{mydata.sometimestamp}" /} - fails -

{@intlDate timeZone="UTC" val={mydata.sometimestamp} /} - can't do this since dust fails saying it can't match the brackets

@ericf
Copy link
Collaborator

ericf commented Jun 13, 2014

So you're saying that Dust only supports data that's a String being passed to helpers?

@fhemberger
Copy link
Contributor

Demo:

var tmpl = '<time>{@intlDate val={ts} /}</time>';
var ctx = { ts : (new Date()).getTime() };
dust.renderSource(tmpl, ctx, function(err, out) { console.log(out); });
// Dust error message:
// SyntaxError: Expected buffer, comment, partial, raw, reference,
// section or special but "{" found.

@fhemberger
Copy link
Contributor

@ericf You also have a similar issue with one example from your README:

Template: <b>{@intlNumber val=40000.004 /}</b>
Expected: <b>40,000.004</b>
Actual: <b>40,000.4</b>

To get the correct result, you have to pass val as string: <b>{@intlNumber val="40000.004" /}</b>

@drewfish
Copy link
Contributor

Does {@intlDate timeZone="UTC" val=mydata.sometimestamp /} work?

@fhemberger
Copy link
Contributor

This works for me, but for verbosity you may want to consider the change I proposed in #26 (comment).

@sfj2
Copy link
Author

sfj2 commented Jun 16, 2014

@drewfish that seems to work. thanks!. but it might be good to fix this to accept string too.

@redonkulus
Copy link
Member

@sfj2 I'm not sure its needed. That just how Dust works, you don't need the quotes or brackets to pass in context values.

@sfj2
Copy link
Author

sfj2 commented Jun 17, 2014

Agree @redonkulus. Maybe then we should fix the readme at least? this is what's there in the readme right now -

var timeStamp = (new Date()).getTime(); // 1395872439650
var tmpl = '{@intlDate val="' + timeStamp + '" /}';

and maybe we should have an example of {@intlDate timeZone="UTC" val=mydata.sometimestamp /} too? i talked to at least 3-4 people who works regularly on dust, and couldn't figure this out :)

@redonkulus
Copy link
Member

Ya I'd say an example like you mention would be useful. This seems to trip up developers more often than we would like.

@fhemberger
Copy link
Contributor

@sfj2 @redonkulus Just look in the PR #26, I've already proposed some fixes for the examples in the README and a note about timestamps. This should do the trick.

@ericf ericf added this to the v1.0.0 milestone Aug 20, 2014
@ericf
Copy link
Collaborator

ericf commented Aug 25, 2014

This relates to #35

@ericf ericf added the docs label Aug 25, 2014
@drewfish drewfish modified the milestone: v1.0.0 Oct 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants