Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: betsol/time-delta
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: aminya/time-delta
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 18, 2022

  1. Copy the full SHA
    b5383e5 View commit details
  2. fix: accept number in format

    aminya committed Apr 18, 2022
    Copy the full SHA
    97b52bb View commit details
  3. Copy the full SHA
    a6f8423 View commit details
  4. Copy the full SHA
    45cbe22 View commit details
  5. Copy the full SHA
    69d91a4 View commit details
Showing with 20 additions and 4 deletions.
  1. +9 −2 README.md
  2. +3 −1 lib/time-delta.js
  3. +8 −1 types/index.d.ts
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ Formats difference between two dates as a human-readable string in almost any la

### Node.js

In Node.js environment library will load requested locales automatically.
In Node.js environment library will load requested locales automatically from a relative path.

```js
const timeDelta = require('time-delta');
@@ -63,20 +63,27 @@ This ensures minimal size of your application bundle.
```js
// Importing the library
import * as timeDelta from 'time-delta';
import * as numerous from 'numerous';

// Importing locales that you want to use
import enLocale from 'time-delta/locales/en';
import numerousEnLocale from 'numerous/locales/en';
import ruLocale from 'time-delta/locales/ru';
import numerousRuLocale from 'numerous/locales/ru';

// Registering locale
timeDelta.addLocale(enLocale);
numerous.addLocale(numerousEnLocale);


// You can register multiple locales
timeDelta.addLocale([enLocale, ruLocale]);
timeDelta.addLocale([numerousEnLocale, numerousRuLocale]);

// Creating an instance
const instance = timeDelta.create({
locale: 'en', // default
locale: 'en',
autoloadLocales: false
});

const date1 = new Date('2015-04-01T21:00:00');
4 changes: 3 additions & 1 deletion lib/time-delta.js
Original file line number Diff line number Diff line change
@@ -211,7 +211,9 @@ function requireLocale(localeId) {
);

} catch (error) {
throw Error(`Failed to load locale: ${localeId}`);
throw Error(
`Failed to load locale: ${localeId} from ../locales/${localeId}.js. If using a bundled time-delta, set 'autoloadLocales: false' in the config: ${error}`
);

}
}
9 changes: 8 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -25,11 +25,18 @@ export interface Locale {
}

export interface Formatter {
format(firstDate: Date, secondDate: Date, options?: Config);
/**
* Returns difference between two dates as a text string.
*/
format(firstDate: Date | number, secondDate: Date | number, options?: Config): string;
}

export function create(config?: Config): Formatter;

/**
* Adds pluralization data for the specified locale.
* Should be called in browser.
*/
export function addLocale(localeData: (Locale | Locale[]));

export const defaultConfig: Config;