Skip to content

Commit

Permalink
update README, fix examples, references to old js-joda-locale package
Browse files Browse the repository at this point in the history
  • Loading branch information
phueper committed Nov 1, 2018
1 parent 63e6603 commit dacc9e5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions README.md
Expand Up @@ -71,52 +71,57 @@ Install joda using npm
npm install @js-joda/locale
```

To enable js-joda-locale you will onlye need to require it, requireing it automatically registers the locale extensions in the base `js-joda`
To enable js-joda-locale you will only need to require it, requiring it automatically registers the locale extensions in the base `js-joda`
Note: the `Locale` class is exported by `@js-joda/locale` so in order to use it, you will need to extract it from there.

```javascript
require('js-joda-locale')
require('@js-joda/locale_<locale>')
```
since `js-joda-locale` requires `js-joda-timezone` it will also need to be provided, as shown
in the following examples

NOTE: if you are using a destructuring assignment in ES6, it should only be performed *after*
the plugin `use`

### es5

```javascript
const joda = require('js-joda');
require('js-joda-timezone');

const {
DateTimeFormatter,
ZonedDateTime,
ZoneId,
} = joda;
} = require('js-joda');
require('js-joda-timezone');

const {
Locale,
} = require('js-joda-locale');
} = require('@js-joda/locale_en-us');

var zdt = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.of('Europe/Berlin'));
console.log('en_US formatted string:', zdt.format(DateTimeFormatter.ofPattern('eeee MMMM dd yyyy GGGG, hh:mm:ss a zzzz, \'Week \' ww, \'Quarter \' QQQ').withLocale(Locale.US)));
```
this will output `en_US formatted string: Friday January 01 2016 Anno Domini, 12:00:00 AM Central European Time, Week 01, Quarter Q1`

also see [examples/usage_node.js](examples/usage_node.js) or [examples/usage_node_build.js](examples/usage_node_build.js)

### es6

```ecmascript 6
import { DateTimeFormatter, ZonedDateTime, ZoneId } from 'js-joda';
import 'js-joda-timezone';
import { Locale } from './build/js-joda-locale';
import { Locale } from '.@js-joda/locale_en-us';
const zdt = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.of('Europe/Berlin'));
console.log('en_US formatted string:', zdt.format(DateTimeFormatter.ofPattern('eeee MMMM dd yyyy GGGG, hh:mm:ss a zzzz, \'Week \' ww, \'Quarter \' QQQ').withLocale(Locale.US)));
```

also see the [example](examples/usage_es6.js)

### using prebuilt locale files from core `@js-joda/locale`

If you prefer to download `@js-joda/locale` as a single dependency (albeit a rather large one in terms of download size), all prebuilt locale packages are also included.
You still need to load the separate locale packages, this can be done e.g.
```javascript
require('@js-joda/locale/dist/prebuilt/en-us');
```

### Browser
- using requirejs to load
- might also be possible with the bower version of cldr-data
Expand Down

0 comments on commit dacc9e5

Please sign in to comment.