Skip to content

Fix code examples in README #28

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

Merged
merged 3 commits into from
Aug 7, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define(['dust', 'dust-helper-intl'], function(Dust, DustHelperIntl) {
NOTE: We will use the following variables in the examples:

```js
var dateString = (new Date()).toString(); // 'Wed Mar 26 2014 15:18:48 GMT-0700 (PDT)'
var dateStr = (new Date()).toString(); // 'Wed Mar 26 2014 15:18:48 GMT-0700 (PDT)'
var timeStamp = (new Date()).getTime(); // 1395872439650
```

Expand All @@ -79,10 +79,18 @@ Output:
```

####Convert from timestamp

Template:

```js
var tmpl = '<time>{@intlDate val="' + timeStamp + '" /}</time>';
var tmpl = '<time>{@intlDate val=' + timeStamp + ' /}</time>';
```

or

```js
var tmpl = '<time>{@intlDate val={timeStamp} /}</time>';
var ctx = { timeStamp : (new Date()).getTime() };
```

Output:
Expand All @@ -91,11 +99,14 @@ Output:
<time>3/26/2014</time>
```

> **Note**: Timestamps are always numeric values, passing them as String will fail (see JavaScript Date constructor).


####Formatting the output
Template:

```js
var tmpl = '<time>{@intlDate val=' + dateStr + ' hour="numeric" minute="numeric" timeZone="UTC"/}</time>';
var tmpl = '<time>{@intlDate val="' + dateStr + '" hour="numeric" minute="numeric" timeZone="UTC"/}</time>';
```

Output:
Expand Down Expand Up @@ -127,7 +138,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=40000.004 /}</b>';
var tmpl = '<b>{@intlNumber val="40000.004" /}</b>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the numbers need to be quoted? This seems to be contrary to the approach we suggest for intlDate where the unquoted unixtime is suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integers don't need to be quoted, floats have to. Otherwise Intl will convert this example to 40000.4. You can test it here: http://jsbin.com/gezupene/1/

Of cause, this case wouldn't normally occur when you pass in a variable directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, ok.

```

Output:
Expand All @@ -141,7 +152,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=40000.004 locales="de-DE"/}</b>';
var tmpl = '<b>{@intlNumber val="40000.004" locales="de-DE"/}</b>';
```

Output:
Expand All @@ -154,7 +165,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=40000 style="currency" currency=USD /}</b>';
var tmpl = '<b>{@intlNumber val="40000" style="currency" currency="USD" /}</b>';
```

Output:
Expand All @@ -167,7 +178,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=40000 style="currency" currency=EUR /}</b>';
var tmpl = '<b>{@intlNumber val="40000" style="currency" currency="EUR" /}</b>';
```

Output:
Expand All @@ -181,7 +192,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=40000 style="currency" currency=JPY /}</b>';
var tmpl = '<b>{@intlNumber val="40000" style="currency" currency="JPY" /}</b>';
```

Output:
Expand All @@ -194,7 +205,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=400 style="percent" /}</b>';
var tmpl = '<b>{@intlNumber val="400" style="percent" /}</b>';
```

Output:
Expand All @@ -207,7 +218,7 @@ Output:
Template:

```js
var tmpl = '<b>{@intlNumber val=400 style="percent" locales="de-DE" /}</b>';
var tmpl = '<b>{@intlNumber val="400" style="percent" locales="de-DE" /}</b>';
```

Output:
Expand Down