├── ember-dayjs
├── src
│ ├── .gitkeep
│ ├── helpers
│ │ ├── now.js
│ │ ├── unix.js
│ │ ├── local.js
│ │ ├── dayjs-end-of.js
│ │ ├── dayjs-is-dayjs.js
│ │ ├── dayjs-start-of.js
│ │ ├── dayjs-day-of-week.js
│ │ ├── dayjs-add.js
│ │ ├── dayjs-date-of-month.js
│ │ ├── dayjs-is-after.js
│ │ ├── dayjs-is-same.js
│ │ ├── dayjs-is-before.js
│ │ ├── dayjs-subtract.js
│ │ ├── dayjs-months.js
│ │ ├── dayjs-tz.js
│ │ ├── dayjs-weekdays.js
│ │ ├── dayjs-weekday.js
│ │ ├── dayjs-calendar.js
│ │ ├── dayjs-duration.js
│ │ ├── dayjs-months-short.js
│ │ ├── dayjs-weekdays-min.js
│ │ ├── dayjs-week-of-year.js
│ │ ├── dayjs-weekdays-short.js
│ │ ├── dayjs-days-in-month.js
│ │ ├── dayjs-diff.js
│ │ ├── dayjs-is-leap-year.js
│ │ ├── dayjs-day-of-year.js
│ │ ├── dayjs-to-now.js
│ │ ├── dayjs-to.js
│ │ ├── dayjs-from-now.js
│ │ ├── dayjs-from.js
│ │ ├── dayjs-is-same-or-after.js
│ │ ├── dayjs-is-same-or-before.js
│ │ ├── dayjs-is-between.js
│ │ ├── utc.js
│ │ ├── dayjs-duration-humanize.js
│ │ ├── dayjs.js
│ │ ├── base-helper.js
│ │ └── dayjs-format.js
│ └── services
│ │ └── dayjs.js
├── .eslintignore
├── addon-main.cjs
├── babel.config.json
├── .prettierrc.js
├── .template-lintrc.js
├── .prettierignore
├── .gitignore
├── LICENSE.md
├── .eslintrc.js
├── rollup.config.mjs
├── package.json
└── README.md
├── test-app
├── app
│ ├── models
│ │ └── .gitkeep
│ ├── routes
│ │ └── .gitkeep
│ ├── styles
│ │ └── app.css
│ ├── components
│ │ └── .gitkeep
│ ├── controllers
│ │ ├── .gitkeep
│ │ └── application.js
│ ├── helpers
│ │ └── .gitkeep
│ ├── router.js
│ ├── templates
│ │ └── application.hbs
│ ├── app.js
│ └── index.html
├── tests
│ ├── unit
│ │ └── .gitkeep
│ ├── integration
│ │ ├── .gitkeep
│ │ └── helpers
│ │ │ └── dayjs-test.js
│ ├── test-helper.js
│ ├── index.html
│ └── helpers
│ │ └── index.js
├── .watchmanconfig
├── public
│ └── robots.txt
├── config
│ ├── optional-features.json
│ ├── targets.js
│ ├── ember-cli-update.json
│ ├── environment.js
│ └── ember-try.js
├── .prettierrc.js
├── .template-lintrc.js
├── ember-cli-build.js
├── .eslintignore
├── .prettierignore
├── .ember-cli
├── .gitignore
├── testem.js
├── .eslintrc.js
└── package.json
├── .prettierrc.js
├── .babelrc
├── jsconfig.json
├── .editorconfig
├── .prettierignore
├── .gitignore
├── CONTRIBUTING.md
├── package.json
├── CHANGELOG.md
├── LICENSE.md
├── .github
├── dependabot.yml
└── workflows
│ └── ci.yml
└── README.md
/ember-dayjs/src/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/models/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/routes/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/styles/app.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/tests/unit/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/app/helpers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/tests/integration/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test-app/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {
2 | "ignore_dirs": ["tmp", "dist"]
3 | }
4 |
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | singleQuote: true,
5 | };
6 |
--------------------------------------------------------------------------------
/test-app/public/robots.txt:
--------------------------------------------------------------------------------
1 | # http://www.robotstxt.org
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/now.js:
--------------------------------------------------------------------------------
1 | import Dayjs from './dayjs';
2 |
3 | export default class Now extends Dayjs {}
4 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/unix.js:
--------------------------------------------------------------------------------
1 | import Dayjs from './dayjs';
2 |
3 | export default class Unix extends Dayjs {}
4 |
--------------------------------------------------------------------------------
/ember-dayjs/.eslintignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 |
4 | # compiled output
5 | /dist/
6 |
7 | # misc
8 | /coverage/
9 |
--------------------------------------------------------------------------------
/ember-dayjs/addon-main.cjs:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const { addonV1Shim } = require('@embroider/addon-shim');
4 |
5 | module.exports = addonV1Shim(__dirname);
6 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | ["@babel/plugin-proposal-decorators", { "legacy": true }],
4 | ["@babel/plugin-proposal-class-properties", { "loose": true }]
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/jsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es6",
4 | "experimentalDecorators": true
5 | },
6 | "exclude": ["node_modules", "bower_components", "tmp", "vendor", ".git", "dist"]
7 | }
8 |
--------------------------------------------------------------------------------
/test-app/config/optional-features.json:
--------------------------------------------------------------------------------
1 | {
2 | "application-template-wrapper": false,
3 | "default-async-observers": true,
4 | "jquery-integration": false,
5 | "template-only-glimmer-components": true
6 | }
7 |
--------------------------------------------------------------------------------
/test-app/.prettierrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | overrides: [
5 | {
6 | files: '*.{js,ts}',
7 | options: {
8 | singleQuote: true,
9 | },
10 | },
11 | ],
12 | };
13 |
--------------------------------------------------------------------------------
/test-app/config/targets.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const browsers = [
4 | 'last 1 Chrome versions',
5 | 'last 1 Firefox versions',
6 | 'last 1 Safari versions',
7 | ];
8 |
9 | module.exports = {
10 | browsers,
11 | };
12 |
--------------------------------------------------------------------------------
/ember-dayjs/babel.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "@embroider/addon-dev/template-colocation-plugin",
4 | ["@babel/plugin-proposal-decorators", { "legacy": true }],
5 | "@babel/plugin-proposal-class-properties"
6 | ]
7 | }
8 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/local.js:
--------------------------------------------------------------------------------
1 | import UtcHelper from './utc';
2 |
3 | export default class Local extends UtcHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return super.compute(params).local();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-end-of.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsEndOf extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self().endOf(params[0]);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-dayjs.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsDayjs extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self.isDayjs(params[0]);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-start-of.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsStartOf extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self().startOf(params[0]);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-day-of-week.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDayOfWeek extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).day(params[1]);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-add.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsAdd extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).add(params[1], hash.precision);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-date-of-month.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDateOfMonth extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).date(params[1]);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/test-app/app/router.js:
--------------------------------------------------------------------------------
1 | import EmberRouter from '@ember/routing/router';
2 | import config from 'test-app/config/environment';
3 |
4 | export default class Router extends EmberRouter {
5 | location = config.locationType;
6 | rootURL = config.rootURL;
7 | }
8 |
9 | Router.map(function () {});
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-after.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsAfter extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).isAfter(params[1], hash.precision);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-same.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsSame extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).isSame(params[1], hash.precision);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-before.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsBefore extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).isBefore(params[1], hash.precision);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-subtract.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsSubtract extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs.self(params[0]).subtract(params[1], hash.precision);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-months.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsMonths extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('localeData');
8 |
9 | return this.dayjs.self.months();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-tz.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsTz extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('timezone');
8 |
9 | return this.dayjs.self.tz(params[0], params[1]);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-weekdays.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsWeekdays extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('localeData');
8 |
9 | return this.dayjs.self.weekdays();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-weekday.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsWeekday extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('weekday');
8 |
9 | return this.dayjs.self().weekday(params[0]);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-calendar.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsCalendar extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('calendar');
8 |
9 | return this.dayjs.self().calendar(...params);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-duration.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDuration extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('duration');
8 |
9 | return this.dayjs.self.duration(...params);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-months-short.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsMonthsShort extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('localeData');
8 |
9 | return this.dayjs.self.monthsShort();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-weekdays-min.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsWeekdaysMin extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('localeData');
8 |
9 | return this.dayjs.self.weekdaysMin();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-week-of-year.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsWeekOfYear extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('weekOfYear');
8 |
9 | return this.dayjs.self(params[0]).week();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-weekdays-short.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsWeekdaysShort extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('localeData');
8 |
9 | return this.dayjs.self.weekdaysShort();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-days-in-month.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDaysInMonth extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('weekday');
8 |
9 | return this.dayjs.self(params[0]).daysInMonth();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-diff.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDiff extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | return this.dayjs
8 | .self(params[0])
9 | .diff(params[1], hash.precision, hash.float || false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-leap-year.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsLeapYear extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('isLeapYear');
8 |
9 | return this.dayjs.self(params[0]).isLeapYear();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-day-of-year.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsDayOfYear extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('dayOfYear');
8 |
9 | return this.dayjs.self(params[0]).dayOfYear(params[1]);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/test-app/app/controllers/application.js:
--------------------------------------------------------------------------------
1 | import { inject as service } from '@ember/service';
2 | import Controller from '@ember/controller';
3 |
4 | export default class ApplicationController extends Controller {
5 | @service dayjs;
6 |
7 | constructor() {
8 | super(...arguments);
9 |
10 | this.dayjs.setLocale('tr');
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-to-now.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsToNow extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('relativeTime');
8 |
9 | return this.dayjs.self(params[0]).toNow(hash.hideAffix || false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-to.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsTo extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('relativeTime');
8 |
9 | return this.dayjs.self(params[0]).to(params[1], hash.hideAffix || false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/.prettierrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | overrides: [
5 | {
6 | files: '*.{js,ts}',
7 | options: {
8 | singleQuote: true,
9 | },
10 | },
11 | ],
12 | importOrderSortSpecifiers: true,
13 | importOrderMergeDuplicateImports: true,
14 | importOrderParserPlugins: ['decorators'],
15 | };
16 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-from-now.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsFromNow extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('relativeTime');
8 |
9 | return this.dayjs.self(params[0]).fromNow(hash.hideAffix || false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-from.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsFrom extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('relativeTime');
8 |
9 | return this.dayjs.self(params[0]).from(params[1], hash.hideAffix || false);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/.template-lintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | extends: 'recommended',
5 | rules: {
6 | 'no-curly-component-invocation': {
7 | allow: ['dayjs', 'dayjs-week-of-year', 'local', 'utc', 'now'],
8 | },
9 | 'no-implicit-this': {
10 | allow: ['dayjs', 'dayjs-week-of-year', 'local', 'utc', 'now'],
11 | },
12 | },
13 | };
14 |
--------------------------------------------------------------------------------
/test-app/.template-lintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | extends: 'recommended',
5 | rules: {
6 | 'no-curly-component-invocation': {
7 | allow: ['dayjs', 'dayjs-week-of-year', 'local', 'utc', 'now'],
8 | },
9 | 'no-implicit-this': {
10 | allow: ['dayjs', 'dayjs-week-of-year', 'local', 'utc', 'now'],
11 | },
12 | },
13 | };
14 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-same-or-after.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsSameOrAfter extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('isSameOrAfter');
8 |
9 | return this.dayjs.self(params[0]).isSameOrAfter(params[1], hash.precision);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-same-or-before.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsSameOrBefore extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('isSameOrBefore');
8 |
9 | return this.dayjs.self(params[0]).isSameOrBefore(params[1], hash.precision);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/test-app/app/templates/application.hbs:
--------------------------------------------------------------------------------
1 | {{dayjs}}
2 |
3 | {{local}}
4 |
5 | {{utc}}
6 |
7 | {{now interval=1000}}
8 |
9 | {{unix 1318781876406}}
10 |
11 | {{dayjs-week-of-year}}
12 |
13 | {{dayjs-to (now) (dayjs-add (now) 7 'day')}}
14 |
15 | {{dayjs-calendar (now)}}
16 |
17 | {{dayjs-duration-humanize 24 'hours'}}
18 |
19 |
--------------------------------------------------------------------------------
/test-app/tests/test-helper.js:
--------------------------------------------------------------------------------
1 | import Application from 'test-app/app';
2 | import config from 'test-app/config/environment';
3 | import * as QUnit from 'qunit';
4 | import { setApplication } from '@ember/test-helpers';
5 | import { setup } from 'qunit-dom';
6 | import { start } from 'ember-qunit';
7 |
8 | setApplication(Application.create(config.APP));
9 |
10 | setup(QUnit.assert);
11 |
12 | start();
13 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-is-between.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsIsBetween extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | this.dayjs.extend('isBetween');
8 |
9 | return this.dayjs
10 | .self(params[0])
11 | .isBetween(params[1], params[2], hash.precision, hash.inclusivity);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test-app/ember-cli-build.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const EmberApp = require('ember-cli/lib/broccoli/ember-app');
4 |
5 | module.exports = function (defaults) {
6 | const app = new EmberApp(defaults, {
7 | // Add options here
8 | autoImport: {
9 | watchDependencies: ['ember-dayjs'],
10 | },
11 | });
12 |
13 | const { maybeEmbroider } = require('@embroider/test-setup');
14 |
15 | return maybeEmbroider(app);
16 | };
17 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/utc.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 | import { typeOf } from '@ember/utils';
3 |
4 | export default class Utc extends BaseHelper {
5 | compute(params, hash) {
6 | super.compute(params, hash);
7 |
8 | this.dayjs.extend('utc');
9 |
10 | if (typeOf(params) === 'object') {
11 | this.dayjs.extend('objectSupport');
12 | }
13 |
14 | return this.dayjs.self.utc(...params);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test-app/app/app.js:
--------------------------------------------------------------------------------
1 | import Application from '@ember/application';
2 | import Resolver from 'ember-resolver';
3 | import loadInitializers from 'ember-load-initializers';
4 | import config from 'test-app/config/environment';
5 |
6 | export default class App extends Application {
7 | modulePrefix = config.modulePrefix;
8 | podModulePrefix = config.podModulePrefix;
9 | Resolver = Resolver;
10 | }
11 |
12 | loadInitializers(App, config.modulePrefix);
13 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 | end_of_line = lf
9 | charset = utf-8
10 | trim_trailing_whitespace = true
11 | insert_final_newline = true
12 | indent_style = space
13 | indent_size = 2
14 |
15 | [*.hbs]
16 | insert_final_newline = false
17 |
18 | [*.{diff,md}]
19 | trim_trailing_whitespace = false
20 |
--------------------------------------------------------------------------------
/test-app/.eslintignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 | /vendor/
4 |
5 | # compiled output
6 | /dist/
7 | /tmp/
8 |
9 | # dependencies
10 | /bower_components/
11 | /node_modules/
12 |
13 | # misc
14 | /coverage/
15 | !.*
16 | .eslintcache
17 |
18 | # ember-try
19 | /.node_modules.ember-try/
20 | /bower.json.ember-try
21 | /npm-shrinkwrap.json.ember-try
22 | /package.json.ember-try
23 | /package-lock.json.ember-try
24 | /yarn.lock.ember-try
25 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 | /vendor/
4 |
5 | # compiled output
6 | /dist/
7 | /tmp/
8 |
9 | # dependencies
10 | /bower_components/
11 | /node_modules/
12 |
13 | # misc
14 | /coverage/
15 | !.*
16 | .eslintcache
17 | .lint-todo/
18 |
19 | # ember-try
20 | /.node_modules.ember-try/
21 | /bower.json.ember-try
22 | /npm-shrinkwrap.json.ember-try
23 | /package.json.ember-try
24 | /package-lock.json.ember-try
25 | /yarn.lock.ember-try
26 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-duration-humanize.js:
--------------------------------------------------------------------------------
1 | import DayjsDurationHelper from './dayjs-duration';
2 |
3 | export default class DayjsDurationHumanize extends DayjsDurationHelper {
4 | compute(params, hash) {
5 | this.dayjs.useLocale(hash.locale || this.dayjs.locale);
6 | this.dayjs.extend('relativeTime');
7 |
8 | return super
9 | .compute(params, hash)
10 | .locale(hash.locale || this.dayjs.locale)
11 | .humanize();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test-app/config/ember-cli-update.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": "1.0.0",
3 | "packages": [
4 | {
5 | "name": "ember-cli",
6 | "version": "4.10.0",
7 | "blueprints": [
8 | {
9 | "name": "addon",
10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output",
11 | "codemodsSource": "ember-addon-codemods-manifest@1",
12 | "isBaseBlueprint": true
13 | }
14 | ]
15 | }
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/test-app/.prettierignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 | /vendor/
4 |
5 | # compiled output
6 | /dist/
7 | /tmp/
8 |
9 | # dependencies
10 | /bower_components/
11 | /node_modules/
12 |
13 | # misc
14 | /coverage/
15 | !.*
16 | .eslintcache
17 | .lint-todo/
18 |
19 | # ember-try
20 | /.node_modules.ember-try/
21 | /bower.json.ember-try
22 | /npm-shrinkwrap.json.ember-try
23 | /package.json.ember-try
24 | /package-lock.json.ember-try
25 | /yarn.lock.ember-try
26 |
--------------------------------------------------------------------------------
/ember-dayjs/.prettierignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 | /vendor/
4 |
5 | # compiled output
6 | /dist/
7 | /tmp/
8 |
9 | # dependencies
10 | /bower_components/
11 | /node_modules/
12 |
13 | # misc
14 | /coverage/
15 | !.*
16 | .eslintcache
17 | .lint-todo/
18 |
19 | # ember-try
20 | /.node_modules.ember-try/
21 | /bower.json.ember-try
22 | /npm-shrinkwrap.json.ember-try
23 | /package.json.ember-try
24 | /package-lock.json.ember-try
25 | /yarn.lock.ember-try
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | dist/
5 |
6 | # dependencies
7 | node_modules/
8 |
9 | # misc
10 | /.env*
11 | /.pnp*
12 | /.pnpm-debug.log
13 | /.sass-cache
14 | .eslintcache
15 | /connect.lock
16 | /coverage/
17 | /libpeerconnection.log
18 | /npm-debug.log*
19 | /testem.log
20 | /yarn-error.log
21 |
22 | # ember-try
23 | /.node_modules.ember-try/
24 | /package.json.ember-try
25 | /yarn.lock.ember-try
26 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 | import { typeOf } from '@ember/utils';
3 |
4 | export default class Dayjs extends BaseHelper {
5 | compute(params, hash) {
6 | super.compute(params, hash);
7 |
8 | this.dayjs.useLocale(hash.locale || this.dayjs.locale);
9 |
10 | if (typeOf(params) === 'object') {
11 | this.dayjs.extend('objectSupport');
12 | }
13 |
14 | return this.dayjs.self(...params).locale(hash.locale || this.dayjs.locale);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test-app/.ember-cli:
--------------------------------------------------------------------------------
1 | {
2 | /**
3 | Ember CLI sends analytics information by default. The data is completely
4 | anonymous, but there are times when you might want to disable this behavior.
5 |
6 | Setting `disableAnalytics` to true will prevent any data from being sent.
7 | */
8 | "disableAnalytics": false,
9 |
10 | /**
11 | Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
12 | rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
13 | */
14 | "isTypeScriptProject": false
15 | }
16 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/base-helper.js:
--------------------------------------------------------------------------------
1 | import Helper from '@ember/component/helper';
2 | import { run } from '@ember/runloop';
3 | import { inject as service } from '@ember/service';
4 |
5 | export default class BaseHelper extends Helper {
6 | @service dayjs;
7 |
8 | compute(_params, hash = {}) {
9 | this.clearTimer();
10 |
11 | if (hash.interval) {
12 | this.intervalTimer = setTimeout(() => {
13 | run(() => this.recompute());
14 | }, parseInt(hash.interval, 10));
15 | }
16 | }
17 |
18 | clearTimer() {
19 | clearTimeout(this.intervalTimer);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ember-dayjs/src/helpers/dayjs-format.js:
--------------------------------------------------------------------------------
1 | import BaseHelper from './base-helper';
2 |
3 | export default class DayjsFormat extends BaseHelper {
4 | compute(params, hash) {
5 | super.compute(params, hash);
6 |
7 | if (hash.inputFormat) {
8 | this.dayjs.extend('customParseFormat');
9 | }
10 |
11 | if (hash.advanced) {
12 | this.dayjs.extend('advancedFormat');
13 | }
14 |
15 | this.dayjs.useLocale(hash.locale || this.dayjs.locale);
16 |
17 | return this.dayjs
18 | .self(params[0], hash.inputFormat)
19 | .locale(hash.locale || this.dayjs.locale)
20 | .format(params[1]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test-app/tests/integration/helpers/dayjs-test.js:
--------------------------------------------------------------------------------
1 | import { module, test } from 'qunit';
2 | import { setupRenderingTest } from 'ember-qunit';
3 | import { render } from '@ember/test-helpers';
4 | import { hbs } from 'ember-cli-htmlbars';
5 |
6 | module('Integration | Helper | dayjs', function (hooks) {
7 | setupRenderingTest(hooks);
8 |
9 | test('format a date', async function (assert) {
10 | this.set('value', '2001-10-31T08:24:56');
11 |
12 | await render(hbs`{{utc this.value}}`);
13 |
14 | assert.strictEqual(
15 | this.element.textContent.trim(),
16 | 'Wed, 31 Oct 2001 08:24:56 GMT'
17 | );
18 | });
19 | });
20 |
--------------------------------------------------------------------------------
/test-app/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist/
5 | /tmp/
6 |
7 | # dependencies
8 | /bower_components/
9 | /node_modules/
10 |
11 | # misc
12 | /.env*
13 | /.pnp*
14 | /.sass-cache
15 | /.eslintcache
16 | /connect.lock
17 | /coverage/
18 | /libpeerconnection.log
19 | /npm-debug.log*
20 | /testem.log
21 | /yarn-error.log
22 |
23 | # ember-try
24 | /.node_modules.ember-try/
25 | /bower.json.ember-try
26 | /npm-shrinkwrap.json.ember-try
27 | /package.json.ember-try
28 | /package-lock.json.ember-try
29 | /yarn.lock.ember-try
30 |
31 | # broccoli-debug
32 | /DEBUG/
33 | node_modules
34 | dist
35 | .eslintcache
36 |
--------------------------------------------------------------------------------
/ember-dayjs/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist/
5 | /tmp/
6 |
7 | # dependencies
8 | /bower_components/
9 | /node_modules/
10 |
11 | # misc
12 | /.env*
13 | /.pnp*
14 | /.sass-cache
15 | /.eslintcache
16 | /connect.lock
17 | /coverage/
18 | /libpeerconnection.log
19 | /npm-debug.log*
20 | /testem.log
21 | /yarn-error.log
22 |
23 | # ember-try
24 | /.node_modules.ember-try/
25 | /bower.json.ember-try
26 | /npm-shrinkwrap.json.ember-try
27 | /package.json.ember-try
28 | /package-lock.json.ember-try
29 | /yarn.lock.ember-try
30 |
31 | # broccoli-debug
32 | /DEBUG/
33 | node_modules
34 | dist
35 | .eslintcache
36 |
--------------------------------------------------------------------------------
/test-app/testem.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | test_page: 'tests/index.html?hidepassed',
5 | disable_watching: true,
6 | launch_in_ci: ['Chrome'],
7 | launch_in_dev: ['Chrome'],
8 | browser_start_timeout: 120,
9 | browser_args: {
10 | Chrome: {
11 | ci: [
12 | // --no-sandbox is needed when running Chrome inside a container
13 | process.env.CI ? '--no-sandbox' : null,
14 | '--headless',
15 | '--disable-dev-shm-usage',
16 | '--disable-software-rasterizer',
17 | '--mute-audio',
18 | '--remote-debugging-port=0',
19 | '--window-size=1440,900',
20 | ].filter(Boolean),
21 | },
22 | },
23 | };
24 |
--------------------------------------------------------------------------------
/test-app/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dummy
6 |
7 |
8 |
9 | {{content-for "head"}}
10 |
11 |
12 |
13 |
14 | {{content-for "head-footer"}}
15 |
16 |
17 | {{content-for "body"}}
18 |
19 |
20 |
21 |
22 | {{content-for "body-footer"}}
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How To Contribute
2 |
3 | ## Installation
4 |
5 | * `git clone `
6 | * `cd ember-dayjs`
7 | * `npm install`
8 |
9 | ## Linting
10 |
11 | * `npm run lint:hbs`
12 | * `npm run lint:js`
13 | * `npm run lint:js -- --fix`
14 |
15 | ## Running tests
16 |
17 | * `ember test` – Runs the test suite on the current Ember version
18 | * `ember test --server` – Runs the test suite in "watch mode"
19 | * `ember try:each` – Runs the test suite against multiple Ember versions
20 |
21 | ## Running the dummy application
22 |
23 | * `ember serve`
24 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200).
25 |
26 | For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/).
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ember-dayjs",
3 | "version": "0.0.1",
4 | "private": true,
5 | "repository": "",
6 | "license": "MIT",
7 | "author": "",
8 | "workspaces": [
9 | "ember-dayjs",
10 | "test-app"
11 | ],
12 | "scripts": {
13 | "build": "npm run build --workspace ember-dayjs",
14 | "lint": "npm run lint --workspaces --if-present",
15 | "lint:fix": "npm run lint:fix --workspaces --if-present",
16 | "prepare": "npm run build",
17 | "start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
18 | "start:addon": "npm start --workspace ember-dayjs",
19 | "start:test-app": "npm start --workspace test-app",
20 | "test": "npm run test --workspaces --if-present",
21 | "deploy": "npm version patch && git push && git push origin --tags && npm publish --workspace ember-dayjs"
22 | },
23 | "devDependencies": {
24 | "concurrently": "^8.2.2",
25 | "prettier": "^3.2.5"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes will be documented in this file.
4 |
5 | [0.12.2] - 2023-06-01
6 | - You can use advanced format now ({{dayjs-format date "MMMM Do YYYY" advanced=true}}). Thanks [Courtland Allen](https://github.com/courthead)
7 |
8 | [0.12.0] - 2023-06-01
9 | - When locale set we also set globally now. May change the result. Thanks [Xavier Carron](https://github.com/xav-car)
10 |
11 | [0.11.0] - 2023-04-23
12 | - Migrated to v2 - No need for cherry-pick locales or plugins
13 |
14 | [0.4.0] - 2021-05-09
15 |
16 | - A long time mistake has been fixed in dayjs-format. Now it takes 2nd positional param for output format and one named param `inputFormat` for input format. [#122](https://github.com/sinankeskin/ember-dayjs/issues/122) - Thanks [vst](https://github.com/vst)
17 | - A bug in dayjs-duration has been fixed but there is no signature changes.
18 | - ember-cli upgraded to v3.28
19 |
20 | Compatibility is now;
21 | * Ember.js v3.20 or above
22 | * Ember CLI v3.20 or above
23 | * Node.js v12 or above
24 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/ember-dayjs/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/ember-dayjs/src/services/dayjs.js:
--------------------------------------------------------------------------------
1 | import { assert } from '@ember/debug';
2 | import Service from '@ember/service';
3 | import { isBlank } from '@ember/utils';
4 | import { importSync } from '@embroider/macros';
5 | import { tracked } from '@glimmer/tracking';
6 | import dayjs from 'dayjs';
7 |
8 | export default class DayjsService extends Service {
9 | @tracked locale = 'en';
10 |
11 | get self() {
12 | return dayjs;
13 | }
14 |
15 | setLocale(locale) {
16 | this.useLocale(locale);
17 | this.self.locale(locale);
18 | this.locale = locale;
19 | }
20 |
21 | useLocale(locale) {
22 | if (isBlank(locale)) {
23 | return assert('Locale cannot be null.');
24 | }
25 |
26 | importSync(`dayjs/locale/${locale}.js`);
27 | }
28 |
29 | setTimeZone(timeZone) {
30 | this.extend('timezone');
31 |
32 | this.self.tz.setDefault(timeZone);
33 | }
34 |
35 | resetTimezone() {
36 | this.setTimeZone();
37 | }
38 |
39 | extend(pluginName) {
40 | if (isBlank(pluginName)) {
41 | return assert('Plugin name cannot be null.');
42 | }
43 |
44 | const { default: plugin } = importSync(`dayjs/plugin/${pluginName}.js`);
45 |
46 | this.self.extend(plugin);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/test-app/.eslintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | root: true,
5 | parser: '@babel/eslint-parser',
6 | parserOptions: {
7 | ecmaVersion: 2018,
8 | sourceType: 'module',
9 | requireConfigFile: true,
10 | },
11 | plugins: ['ember'],
12 | extends: [
13 | 'eslint:recommended',
14 | 'plugin:ember/recommended',
15 | 'plugin:prettier/recommended',
16 | ],
17 | env: {
18 | browser: true,
19 | },
20 | rules: {},
21 | overrides: [
22 | // node files
23 | {
24 | files: [
25 | './.eslintrc.js',
26 | './.prettierrc.js',
27 | './.template-lintrc.js',
28 | './ember-cli-build.js',
29 | './index.js',
30 | './testem.js',
31 | './blueprints/*/index.js',
32 | './config/**/*.js',
33 | './tests/dummy/config/**/*.js',
34 | ],
35 | parserOptions: {
36 | sourceType: 'script',
37 | },
38 | env: {
39 | browser: false,
40 | node: true,
41 | },
42 | extends: ['plugin:n/recommended'],
43 | },
44 | {
45 | // test files
46 | files: ['tests/**/*-test.{js,ts}'],
47 | extends: ['plugin:qunit/recommended'],
48 | },
49 | ],
50 | };
51 |
--------------------------------------------------------------------------------
/ember-dayjs/.eslintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | root: true,
5 | parser: '@babel/eslint-parser',
6 | parserOptions: {
7 | ecmaVersion: 2018,
8 | sourceType: 'module',
9 | requireConfigFile: true,
10 | },
11 | plugins: ['ember'],
12 | extends: [
13 | 'eslint:recommended',
14 | 'plugin:ember/recommended',
15 | 'plugin:prettier/recommended',
16 | 'plugin:decorator-position/ember',
17 | ],
18 | env: {
19 | browser: true,
20 | },
21 | rules: {},
22 | overrides: [
23 | // node files
24 | {
25 | files: [
26 | './.eslintrc.js',
27 | './.prettierrc.js',
28 | './.template-lintrc.js',
29 | './ember-cli-build.js',
30 | './index.js',
31 | './testem.js',
32 | './blueprints/*/index.js',
33 | './config/**/*.js',
34 | './tests/dummy/config/**/*.js',
35 | ],
36 | parserOptions: {
37 | sourceType: 'script',
38 | },
39 | env: {
40 | browser: false,
41 | node: true,
42 | },
43 | extends: ['plugin:n/recommended'],
44 | },
45 | {
46 | // test files
47 | files: ['tests/**/*-test.{js,ts}'],
48 | extends: ['plugin:qunit/recommended'],
49 | },
50 | ],
51 | };
52 |
--------------------------------------------------------------------------------
/test-app/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dummy Tests
6 |
7 |
8 |
9 | {{content-for "head"}}
10 | {{content-for "test-head"}}
11 |
12 |
13 |
14 |
15 |
16 | {{content-for "head-footer"}}
17 | {{content-for "test-head-footer"}}
18 |
19 |
20 | {{content-for "body"}}
21 | {{content-for "test-body"}}
22 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | {{content-for "body-footer"}}
37 | {{content-for "test-body-footer"}}
38 |
39 |
40 |
--------------------------------------------------------------------------------
/test-app/config/environment.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function (environment) {
4 | const ENV = {
5 | modulePrefix: 'test-app',
6 | environment,
7 | rootURL: '/',
8 | locationType: 'history',
9 | EmberENV: {
10 | EXTEND_PROTOTYPES: false,
11 | FEATURES: {
12 | // Here you can enable experimental features on an ember canary build
13 | // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
14 | },
15 | },
16 |
17 | APP: {
18 | // Here you can pass flags/options to your application instance
19 | // when it is created
20 | },
21 | };
22 |
23 | if (environment === 'development') {
24 | // ENV.APP.LOG_RESOLVER = true;
25 | // ENV.APP.LOG_ACTIVE_GENERATION = true;
26 | // ENV.APP.LOG_TRANSITIONS = true;
27 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
28 | // ENV.APP.LOG_VIEW_LOOKUPS = true;
29 | }
30 |
31 | if (environment === 'test') {
32 | // Testem prefers this...
33 | ENV.locationType = 'none';
34 |
35 | // keep test console output quieter
36 | ENV.APP.LOG_ACTIVE_GENERATION = false;
37 | ENV.APP.LOG_VIEW_LOOKUPS = false;
38 |
39 | ENV.APP.rootElement = '#ember-testing';
40 | ENV.APP.autoboot = false;
41 | }
42 |
43 | if (environment === 'production') {
44 | // here you can enable a production-specific feature
45 | }
46 |
47 | return ENV;
48 | };
49 |
--------------------------------------------------------------------------------
/test-app/tests/helpers/index.js:
--------------------------------------------------------------------------------
1 | import {
2 | setupApplicationTest as upstreamSetupApplicationTest,
3 | setupRenderingTest as upstreamSetupRenderingTest,
4 | setupTest as upstreamSetupTest,
5 | } from 'ember-qunit';
6 |
7 | // This file exists to provide wrappers around ember-qunit's / ember-mocha's
8 | // test setup functions. This way, you can easily extend the setup that is
9 | // needed per test type.
10 |
11 | function setupApplicationTest(hooks, options) {
12 | upstreamSetupApplicationTest(hooks, options);
13 |
14 | // Additional setup for application tests can be done here.
15 | //
16 | // For example, if you need an authenticated session for each
17 | // application test, you could do:
18 | //
19 | // hooks.beforeEach(async function () {
20 | // await authenticateSession(); // ember-simple-auth
21 | // });
22 | //
23 | // This is also a good place to call test setup functions coming
24 | // from other addons:
25 | //
26 | // setupIntl(hooks); // ember-intl
27 | // setupMirage(hooks); // ember-cli-mirage
28 | }
29 |
30 | function setupRenderingTest(hooks, options) {
31 | upstreamSetupRenderingTest(hooks, options);
32 |
33 | // Additional setup for rendering tests can be done here.
34 | }
35 |
36 | function setupTest(hooks, options) {
37 | upstreamSetupTest(hooks, options);
38 |
39 | // Additional setup for unit tests can be done here.
40 | }
41 |
42 | export { setupApplicationTest, setupRenderingTest, setupTest };
43 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "03:00"
8 | open-pull-requests-limit: 10
9 | ignore:
10 | - dependency-name: ember-cli-babel
11 | versions:
12 | - 7.25.0
13 | - 7.26.4
14 | - dependency-name: ember-cli-terser
15 | versions:
16 | - 4.0.2
17 | - dependency-name: eslint-config-prettier
18 | versions:
19 | - 8.0.0
20 | - 8.1.0
21 | - 8.3.0
22 | - dependency-name: ember-cli
23 | versions:
24 | - 3.25.0
25 | - 3.25.1
26 | - 3.25.2
27 | - 3.26.1
28 | - dependency-name: eslint-plugin-ember
29 | versions:
30 | - 10.2.0
31 | - 10.3.0
32 | - 10.4.1
33 | - dependency-name: eslint-plugin-prettier
34 | versions:
35 | - 3.4.0
36 | - dependency-name: ember-source
37 | versions:
38 | - 3.25.0
39 | - 3.25.3
40 | - 3.26.0
41 | - 3.26.1
42 | - dependency-name: ember-auto-import
43 | versions:
44 | - 1.11.0
45 | - 1.11.2
46 | - dependency-name: ember-cli-htmlbars
47 | versions:
48 | - 5.4.0
49 | - 5.5.0
50 | - 5.6.2
51 | - 5.6.3
52 | - 5.6.4
53 | - 5.7.0
54 | - 5.7.1
55 | - dependency-name: ember-qunit
56 | versions:
57 | - 5.1.3
58 | - 5.1.4
59 | - dependency-name: ember-template-lint
60 | versions:
61 | - 2.18.0
62 | - 2.18.1
63 | - 2.19.0
64 | - 2.21.0
65 | - 3.0.0
66 | - 3.1.1
67 | - dependency-name: eslint
68 | versions:
69 | - 7.19.0
70 | - 7.20.0
71 | - 7.21.0
72 | - dependency-name: "@ember/test-helpers"
73 | versions:
74 | - 2.2.0
75 | - 2.2.3
76 | - dependency-name: ember-page-title
77 | versions:
78 | - 6.2.1
79 |
--------------------------------------------------------------------------------
/test-app/config/ember-try.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const getChannelURL = require('ember-source-channel-url');
4 | const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');
5 |
6 | module.exports = async function () {
7 | return {
8 | scenarios: [
9 | {
10 | name: 'ember-lts-3.28',
11 | npm: {
12 | devDependencies: {
13 | 'ember-source': '~3.28.0',
14 | },
15 | },
16 | },
17 | {
18 | name: 'ember-lts-4.4',
19 | npm: {
20 | devDependencies: {
21 | 'ember-source': '~4.4.0',
22 | },
23 | },
24 | },
25 | {
26 | name: 'ember-release',
27 | npm: {
28 | devDependencies: {
29 | 'ember-source': await getChannelURL('release'),
30 | },
31 | },
32 | },
33 | {
34 | name: 'ember-beta',
35 | npm: {
36 | devDependencies: {
37 | 'ember-source': await getChannelURL('beta'),
38 | },
39 | },
40 | },
41 | {
42 | name: 'ember-canary',
43 | npm: {
44 | devDependencies: {
45 | 'ember-source': await getChannelURL('canary'),
46 | },
47 | },
48 | },
49 | {
50 | name: 'ember-classic',
51 | env: {
52 | EMBER_OPTIONAL_FEATURES: JSON.stringify({
53 | 'application-template-wrapper': true,
54 | 'default-async-observers': false,
55 | 'template-only-glimmer-components': false,
56 | }),
57 | },
58 | npm: {
59 | devDependencies: {
60 | 'ember-source': '~3.28.0',
61 | },
62 | ember: {
63 | edition: 'classic',
64 | },
65 | },
66 | },
67 | embroiderSafe(),
68 | embroiderOptimized(),
69 | ],
70 | };
71 | };
72 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | - master
8 | pull_request: {}
9 |
10 | concurrency:
11 | group: ci-${{ github.head_ref || github.ref }}
12 | cancel-in-progress: true
13 |
14 | jobs:
15 | test:
16 | name: "Tests"
17 | runs-on: ubuntu-latest
18 | timeout-minutes: 10
19 |
20 | steps:
21 | - uses: actions/checkout@v3
22 | - name: Install Node
23 | uses: actions/setup-node@v3
24 | with:
25 | node-version: 14.x
26 | cache: npm
27 | - name: Install Dependencies
28 | run: npm ci
29 | - name: Lint
30 | run: npm run lint
31 | - name: Run Tests
32 | run: npm run test:ember
33 |
34 | floating:
35 | name: "Floating Dependencies"
36 | runs-on: ubuntu-latest
37 | timeout-minutes: 10
38 |
39 | steps:
40 | - uses: actions/checkout@v3
41 | - uses: actions/setup-node@v3
42 | with:
43 | node-version: 14.x
44 | cache: npm
45 | - name: Install Dependencies
46 | run: npm install --no-shrinkwrap
47 | - name: Run Tests
48 | run: npm run test:ember
49 |
50 | try-scenarios:
51 | name: ${{ matrix.try-scenario }}
52 | runs-on: ubuntu-latest
53 | needs: "test"
54 | timeout-minutes: 10
55 |
56 | strategy:
57 | fail-fast: false
58 | matrix:
59 | try-scenario:
60 | - ember-lts-3.28
61 | - ember-lts-4.4
62 | - ember-release
63 | - ember-beta
64 | - ember-canary
65 | - ember-classic
66 | - embroider-safe
67 | - embroider-optimized
68 |
69 | steps:
70 | - uses: actions/checkout@v3
71 | - name: Install Node
72 | uses: actions/setup-node@v3
73 | with:
74 | node-version: 14.x
75 | cache: npm
76 | - name: Install Dependencies
77 | run: npm ci
78 | - name: Run Tests
79 | run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }}
80 |
--------------------------------------------------------------------------------
/test-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "test-app",
3 | "version": "0.0.0",
4 | "description": "day.js template helpers and a service for Ember.",
5 | "keywords": [
6 | "dayjs",
7 | "ember-dayjs",
8 | "date helpers"
9 | ],
10 | "repository": "https://github.com/sinankeskin/ember-dayjs",
11 | "license": "MIT",
12 | "author": "Sinan Keskin (https://kesk.in)",
13 | "directories": {
14 | "doc": "doc",
15 | "test": "tests"
16 | },
17 | "scripts": {
18 | "build": "ember build --environment=production",
19 | "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
20 | "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
21 | "lint:hbs": "ember-template-lint .",
22 | "lint:hbs:fix": "ember-template-lint . --fix",
23 | "lint:js": "eslint . --cache",
24 | "lint:js:fix": "eslint . --fix",
25 | "start": "ember serve",
26 | "deploy": "npm version patch && git push && git push origin --tags && npm publish",
27 | "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
28 | "test:ember": "ember test",
29 | "test:ember-compatibility": "ember try:each",
30 | "update": "ecu --to latest && ncu -u && npm install && npm run lint:fix && npm run lint && git commit -am \"Update some packages\" && git push",
31 | "update:all": "run-s update deploy"
32 | },
33 | "dependencies": {
34 | "ember-dayjs": "*"
35 | },
36 | "devDependencies": {
37 | "@babel/eslint-parser": "^7.19.1",
38 | "@babel/plugin-proposal-class-properties": "^7.18.6",
39 | "@babel/plugin-proposal-decorators": "^7.20.13",
40 | "@ember/optional-features": "^2.0.0",
41 | "@ember/string": "^3.0.1",
42 | "@ember/test-helpers": "^2.9.3",
43 | "@embroider/test-setup": "^2.1.1",
44 | "@glimmer/component": "^1.1.2",
45 | "@glimmer/tracking": "^1.1.2",
46 | "broccoli-asset-rev": "^3.0.0",
47 | "concurrently": "^7.6.0",
48 | "ember-auto-import": "^2.6.0",
49 | "ember-cli": "~4.10.0",
50 | "ember-cli-babel": "^7.26.11",
51 | "ember-cli-dependency-checker": "^3.3.1",
52 | "ember-cli-htmlbars": "^6.2.0",
53 | "ember-cli-inject-live-reload": "^2.1.0",
54 | "ember-cli-sri": "^2.1.1",
55 | "ember-cli-terser": "^4.0.2",
56 | "ember-load-initializers": "^2.1.2",
57 | "ember-page-title": "^7.0.0",
58 | "ember-qunit": "^6.1.1",
59 | "ember-resolver": "^10.0.0",
60 | "ember-source": "^4.10.0",
61 | "ember-source-channel-url": "^3.0.0",
62 | "ember-template-lint": "^5.3.3",
63 | "ember-try": "^3.0.0-beta.1",
64 | "eslint": "^8.39.0",
65 | "eslint-config-prettier": "^8.6.0",
66 | "eslint-plugin-ember": "^11.4.4",
67 | "eslint-plugin-n": "^15.6.1",
68 | "eslint-plugin-prettier": "^4.2.1",
69 | "eslint-plugin-qunit": "^7.3.4",
70 | "loader.js": "^4.7.0",
71 | "prettier": "^2.8.3",
72 | "qunit": "^2.19.4",
73 | "qunit-dom": "^2.0.0",
74 | "webpack": "^5.75.0"
75 | },
76 | "peerDependencies": {
77 | "ember-source": "^3.28.0 || ^4.0.0"
78 | },
79 | "engines": {
80 | "node": "14.* || 16.* || >= 18"
81 | },
82 | "ember": {
83 | "edition": "octane"
84 | },
85 | "private": true
86 | }
87 |
--------------------------------------------------------------------------------
/ember-dayjs/rollup.config.mjs:
--------------------------------------------------------------------------------
1 | import { babel } from '@rollup/plugin-babel';
2 | import copy from 'rollup-plugin-copy';
3 | import { Addon } from '@embroider/addon-dev/rollup';
4 |
5 | const addon = new Addon({
6 | srcDir: 'src',
7 | destDir: 'dist',
8 | });
9 |
10 | export default {
11 | // This provides defaults that work well alongside `publicEntrypoints` below.
12 | // You can augment this if you need to.
13 | output: addon.output(),
14 |
15 | plugins: [
16 | // These are the modules that users should be able to import from your
17 | // addon. Anything not listed here may get optimized away.
18 | addon.publicEntrypoints(['helpers/base-helper.js', 'helpers/dayjs-add.js', 'helpers/dayjs-calendar.js', 'helpers/dayjs-date-of-month.js', 'helpers/dayjs-day-of-week.js', 'helpers/dayjs-day-of-year.js', 'helpers/dayjs-days-in-month.js', 'helpers/dayjs-diff.js', 'helpers/dayjs-duration-humanize.js', 'helpers/dayjs-duration.js', 'helpers/dayjs-end-of.js', 'helpers/dayjs-format.js', 'helpers/dayjs-from-now.js', 'helpers/dayjs-from.js', 'helpers/dayjs-is-after.js', 'helpers/dayjs-is-before.js', 'helpers/dayjs-is-between.js', 'helpers/dayjs-is-dayjs.js', 'helpers/dayjs-is-leap-year.js', 'helpers/dayjs-is-same-or-after.js', 'helpers/dayjs-is-same-or-before.js', 'helpers/dayjs-is-same.js', 'helpers/dayjs-months-short.js', 'helpers/dayjs-months.js', 'helpers/dayjs-start-of.js', 'helpers/dayjs-subtract.js', 'helpers/dayjs-to-now.js', 'helpers/dayjs-to.js', 'helpers/dayjs-tz.js', 'helpers/dayjs-week-of-year.js', 'helpers/dayjs-weekday.js', 'helpers/dayjs-weekdays-min.js', 'helpers/dayjs-weekdays-short.js', 'helpers/dayjs-weekdays.js', 'helpers/dayjs.js', 'helpers/local.js', 'helpers/now.js', 'helpers/unix.js', 'helpers/utc.js', 'services/dayjs.js']),
19 |
20 | // These are the modules that should get reexported into the traditional
21 | // "app" tree. Things in here should also be in publicEntrypoints above, but
22 | // not everything in publicEntrypoints necessarily needs to go here.
23 | addon.appReexports(['helpers/base-helper.js', 'helpers/dayjs-add.js', 'helpers/dayjs-calendar.js', 'helpers/dayjs-date-of-month.js', 'helpers/dayjs-day-of-week.js', 'helpers/dayjs-day-of-year.js', 'helpers/dayjs-days-in-month.js', 'helpers/dayjs-diff.js', 'helpers/dayjs-duration-humanize.js', 'helpers/dayjs-duration.js', 'helpers/dayjs-end-of.js', 'helpers/dayjs-format.js', 'helpers/dayjs-from-now.js', 'helpers/dayjs-from.js', 'helpers/dayjs-is-after.js', 'helpers/dayjs-is-before.js', 'helpers/dayjs-is-between.js', 'helpers/dayjs-is-dayjs.js', 'helpers/dayjs-is-leap-year.js', 'helpers/dayjs-is-same-or-after.js', 'helpers/dayjs-is-same-or-before.js', 'helpers/dayjs-is-same.js', 'helpers/dayjs-months-short.js', 'helpers/dayjs-months.js', 'helpers/dayjs-start-of.js', 'helpers/dayjs-subtract.js', 'helpers/dayjs-to-now.js', 'helpers/dayjs-to.js', 'helpers/dayjs-tz.js', 'helpers/dayjs-week-of-year.js', 'helpers/dayjs-weekday.js', 'helpers/dayjs-weekdays-min.js', 'helpers/dayjs-weekdays-short.js', 'helpers/dayjs-weekdays.js', 'helpers/dayjs.js', 'helpers/local.js', 'helpers/now.js', 'helpers/unix.js', 'helpers/utc.js', 'services/dayjs.js']),
24 |
25 | // Follow the V2 Addon rules about dependencies. Your code can import from
26 | // `dependencies` and `peerDependencies` as well as standard Ember-provided
27 | // package names.
28 | addon.dependencies(),
29 |
30 | // This babel config should *not* apply presets or compile away ES modules.
31 | // It exists only to provide development niceties for you, like automatic
32 | // template colocation.
33 | //
34 | // By default, this will load the actual babel config from the file
35 | // babel.config.json.
36 | babel({
37 | babelHelpers: 'bundled',
38 | }),
39 |
40 | // Ensure that standalone .hbs files are properly integrated as Javascript.
41 | addon.hbs(),
42 |
43 | // addons are allowed to contain imports of .css files, which we want rollup
44 | // to leave alone and keep in the published output.
45 | addon.keepAssets(['**/*.css']),
46 |
47 | // Remove leftover build artifacts when starting a new build.
48 | addon.clean(),
49 |
50 | // Copy Readme and License into published package
51 | copy({
52 | targets: [
53 | { src: '../README.md', dest: '.' },
54 | { src: '../LICENSE.md', dest: '.' },
55 | ],
56 | }),
57 | ],
58 | };
59 |
--------------------------------------------------------------------------------
/ember-dayjs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ember-dayjs",
3 | "version": "0.12.4",
4 | "description": "day.js template helpers and a service for Ember.",
5 | "keywords": [
6 | "ember-addon",
7 | "dayjs",
8 | "ember-dayjs",
9 | "date helpers"
10 | ],
11 | "repository": "https://github.com/sinankeskin/ember-dayjs",
12 | "license": "MIT",
13 | "author": "Sinan Keskin (https://kesk.in)",
14 | "directories": {
15 | "doc": "doc",
16 | "test": "tests"
17 | },
18 | "scripts": {
19 | "build": "rollup --config",
20 | "deploy": "npm version patch && git push && git push origin --tags && npm publish",
21 | "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
22 | "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
23 | "lint:hbs": "ember-template-lint .",
24 | "lint:hbs:fix": "ember-template-lint . --fix",
25 | "lint:js": "eslint . --cache",
26 | "lint:js:fix": "eslint . --fix",
27 | "prepack": "rollup --config",
28 | "start": "rollup --config --watch",
29 | "test": "echo 'A v2 addon does not have tests, run tests in test-app'",
30 | "test:ember": "ember test",
31 | "test:ember-compatibility": "ember try:each",
32 | "update": "ecu --to latest && ncu -u && npm install && npm run lint:fix && npm run lint && git commit -am \"Update some packages\" && git push",
33 | "update:all": "run-s update deploy"
34 | },
35 | "dependencies": {
36 | "@embroider/addon-shim": "^1.8.9",
37 | "@embroider/macros": "^1.16.1",
38 | "dayjs": "^1.11.11"
39 | },
40 | "devDependencies": {
41 | "@babel/core": "^7.24.6",
42 | "@babel/plugin-proposal-class-properties": "^7.18.6",
43 | "@babel/plugin-proposal-decorators": "^7.24.6",
44 | "@embroider/addon-dev": "^4.3.1",
45 | "@ianvs/prettier-plugin-sort-imports": "^4.2.1",
46 | "@rollup/plugin-babel": "^6.0.4",
47 | "eslint-plugin-decorator-position": "^5.0.2",
48 | "rollup": "^4.18.0",
49 | "rollup-plugin-copy": "^3.5.0"
50 | },
51 | "peerDependencies": {
52 | "ember-source": "^3.28.0 || ^4.0.0 || ^5.0.0"
53 | },
54 | "engines": {
55 | "node": "14.* || 16.* || >= 18"
56 | },
57 | "ember": {
58 | "edition": "octane"
59 | },
60 | "ember-addon": {
61 | "app-js": {
62 | "./helpers/base-helper.js": "./dist/_app_/helpers/base-helper.js",
63 | "./helpers/dayjs-add.js": "./dist/_app_/helpers/dayjs-add.js",
64 | "./helpers/dayjs-calendar.js": "./dist/_app_/helpers/dayjs-calendar.js",
65 | "./helpers/dayjs-date-of-month.js": "./dist/_app_/helpers/dayjs-date-of-month.js",
66 | "./helpers/dayjs-day-of-week.js": "./dist/_app_/helpers/dayjs-day-of-week.js",
67 | "./helpers/dayjs-day-of-year.js": "./dist/_app_/helpers/dayjs-day-of-year.js",
68 | "./helpers/dayjs-days-in-month.js": "./dist/_app_/helpers/dayjs-days-in-month.js",
69 | "./helpers/dayjs-diff.js": "./dist/_app_/helpers/dayjs-diff.js",
70 | "./helpers/dayjs-duration-humanize.js": "./dist/_app_/helpers/dayjs-duration-humanize.js",
71 | "./helpers/dayjs-duration.js": "./dist/_app_/helpers/dayjs-duration.js",
72 | "./helpers/dayjs-end-of.js": "./dist/_app_/helpers/dayjs-end-of.js",
73 | "./helpers/dayjs-format.js": "./dist/_app_/helpers/dayjs-format.js",
74 | "./helpers/dayjs-from-now.js": "./dist/_app_/helpers/dayjs-from-now.js",
75 | "./helpers/dayjs-from.js": "./dist/_app_/helpers/dayjs-from.js",
76 | "./helpers/dayjs-is-after.js": "./dist/_app_/helpers/dayjs-is-after.js",
77 | "./helpers/dayjs-is-before.js": "./dist/_app_/helpers/dayjs-is-before.js",
78 | "./helpers/dayjs-is-between.js": "./dist/_app_/helpers/dayjs-is-between.js",
79 | "./helpers/dayjs-is-dayjs.js": "./dist/_app_/helpers/dayjs-is-dayjs.js",
80 | "./helpers/dayjs-is-leap-year.js": "./dist/_app_/helpers/dayjs-is-leap-year.js",
81 | "./helpers/dayjs-is-same-or-after.js": "./dist/_app_/helpers/dayjs-is-same-or-after.js",
82 | "./helpers/dayjs-is-same-or-before.js": "./dist/_app_/helpers/dayjs-is-same-or-before.js",
83 | "./helpers/dayjs-is-same.js": "./dist/_app_/helpers/dayjs-is-same.js",
84 | "./helpers/dayjs-months-short.js": "./dist/_app_/helpers/dayjs-months-short.js",
85 | "./helpers/dayjs-months.js": "./dist/_app_/helpers/dayjs-months.js",
86 | "./helpers/dayjs-start-of.js": "./dist/_app_/helpers/dayjs-start-of.js",
87 | "./helpers/dayjs-subtract.js": "./dist/_app_/helpers/dayjs-subtract.js",
88 | "./helpers/dayjs-to-now.js": "./dist/_app_/helpers/dayjs-to-now.js",
89 | "./helpers/dayjs-to.js": "./dist/_app_/helpers/dayjs-to.js",
90 | "./helpers/dayjs-tz.js": "./dist/_app_/helpers/dayjs-tz.js",
91 | "./helpers/dayjs-week-of-year.js": "./dist/_app_/helpers/dayjs-week-of-year.js",
92 | "./helpers/dayjs-weekday.js": "./dist/_app_/helpers/dayjs-weekday.js",
93 | "./helpers/dayjs-weekdays-min.js": "./dist/_app_/helpers/dayjs-weekdays-min.js",
94 | "./helpers/dayjs-weekdays-short.js": "./dist/_app_/helpers/dayjs-weekdays-short.js",
95 | "./helpers/dayjs-weekdays.js": "./dist/_app_/helpers/dayjs-weekdays.js",
96 | "./helpers/dayjs.js": "./dist/_app_/helpers/dayjs.js",
97 | "./helpers/local.js": "./dist/_app_/helpers/local.js",
98 | "./helpers/now.js": "./dist/_app_/helpers/now.js",
99 | "./helpers/unix.js": "./dist/_app_/helpers/unix.js",
100 | "./helpers/utc.js": "./dist/_app_/helpers/utc.js",
101 | "./services/dayjs.js": "./dist/_app_/services/dayjs.js"
102 | },
103 | "main": "addon-main.cjs",
104 | "type": "addon",
105 | "version": 2
106 | },
107 | "exports": {
108 | ".": "./dist/index.js",
109 | "./*": "./dist/*.js",
110 | "./addon-main.js": "./addon-main.cjs"
111 | },
112 | "files": [
113 | "addon-main.cjs",
114 | "dist"
115 | ]
116 | }
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ember-dayjs
2 |
3 | [day.js](https://day.js.org/) template helpers and a service for Ember.
4 | Nearly drop-in replacement for [ember-moment](https://github.com/stefanpenner/ember-moment).
5 | Just replace all `moment-` with `dayjs-` and try.
6 |
7 | ## Compatibility
8 |
9 | - Ember.js v3.28 or above
10 | - Embroider or ember-auto-import v2
11 |
12 | ## Installation
13 |
14 | ```
15 | ember install ember-dayjs
16 | ```
17 |
18 | ## Usage
19 |
20 | ## Helpers
21 |
22 | ### dayjs
23 |
24 | ```hbs
25 | {{dayjs }}
26 | ```
27 |
28 | | Parameters | Values |
29 | | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
30 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
31 |
32 | Returns a Dayjs.
33 |
34 | ```hbs
35 | {{utc }}
36 | {{utc}}
37 | ```
38 |
39 | | Parameters | Values |
40 | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/plugin/utc#dayjsutc-dayjsutcdatetype-string--number--date--dayjs-format-string) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
42 |
43 | Returns a Dayjs with [UTC mode](http://dayjs.com/docs/#/parsing/utc/) set.
44 |
45 | **Example**
46 |
47 | ```hbs
48 | {{utc '2001-10-31T08:24:56'}}
49 | {{! Wed Oct 31 2001 08:24:56 GMT+0000 }}
50 | {{utc}}
51 | {{! current time utc, like Mon Feb 12 2018 20:33:08 GMT+0000 }}
52 | {{utc (dayjs '2018-01-01T00:00:00+01:00' 'YYYY-MM-DD HH:mm:ssZ')}}
53 | {{! Sun Dec 31 2017 23:00:00 GMT+0000 }}
54 | ```
55 |
56 | ### dayjs-format
57 |
58 | ```hbs
59 | {{dayjs-format [outputFormat=dayjs.defaultFormat] [] []}}
60 | ```
61 |
62 | | Parameters | Values |
63 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
64 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
65 | | `outputFormat` | An optional date/time `String` [output format](https://day.js.org/docs/en/display/format), defaults to `dayjs.defaultFormat` |
66 | | `inputFormat` | An optional named argument for date/time String input format |
67 | | `advanced` | Pass `true` to be able to use [advanced format](https://day.js.org/docs/en/plugin/advanced-format) |
68 |
69 | **Example**
70 |
71 | ```hbs
72 | {{dayjs-format '12-1995-25' 'MM/DD/YYYY' inputFormat='MM-YYYY-DD'}}
73 | {{! 25/12/1995 }}
74 | ```
75 |
76 | ### timezone
77 |
78 | ```hbs
79 | {{dayjs-tz [timeZone]}}
80 | ```
81 |
82 | | Parameters | Values |
83 | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
84 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
85 | | `` | Optional: Time Zone Name Ex: America/Los_Angeles |
86 |
87 | Returns a Dayjs corresponding to the ``.
88 |
89 | **Examples**
90 |
91 | ```hbs
92 | {{dayjs-tz '2014-06-01 12:00' 'America/Los_Angeles'}}
93 | ```
94 |
95 | ### dayjs-from / dayjs-from-now
96 |
97 | ```hbs
98 | {{dayjs-from [] [hideAffix=false]}}
99 | {{dayjs-from-now [hideAffix=false]}}
100 | ```
101 |
102 | | Parameters | Values |
103 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
104 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
105 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...), defaults to now |
106 | | `hideAffix` | An optional `Boolean` to hide the relative prefix/suffix not. |
107 |
108 | Returns the time between `` and `` relative to ``. See [`dayjs#from`](#/docs/#/displaying/from/).
109 |
110 | **Examples**
111 |
112 | ```hbs
113 | {{! in January 2018 at time of writing }}
114 | {{dayjs-from '2995-12-25'}}
115 | {{! in 978 years }}
116 | {{dayjs-from-now '2995-12-25'}}
117 | {{! in 978 years }}
118 | {{dayjs-from '1995-12-25' '2995-12-25' hideAffix=true}}
119 | {{! 1000 years }}
120 | ```
121 |
122 | ### dayjs-to / dayjs-to-now
123 |
124 | ```hbs
125 | {{dayjs-to [] [hideAffix=false]}}
126 | {{dayjs-to-now [hideAffix=false]}}
127 | ```
128 |
129 | | Parameters | Values |
130 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
131 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
132 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...), defaults to now |
133 | | `hideAffix` | An optional `Boolean` to hide the relative prefix/suffix or not. |
134 |
135 | Returns the time between `` and `` relative to ``. See [`dayjs#to`](#/docs/#/displaying/to/).
136 |
137 | _Note that `dayjs-to-now` is just a more verbose `dayjs-to` without `dateB`. You don't need to use it anymore._
138 |
139 | **Examples**
140 |
141 | ```hbs
142 | {{! in January 2018 at time of writing }}
143 | {{dayjs-to '2995-12-25'}}
144 | {{! 978 years ago }}
145 | {{dayjs-to '1995-12-25' '2995-12-25'}}
146 | {{! in 1000 years }}
147 | {{dayjs-to-now '1995-12-25' hideAffix=true}}
148 | {{! 22 years }}
149 | ```
150 |
151 | ### dayjs-duration
152 |
153 | ```hbs
154 | {{dayjs-duration []}}
155 | ```
156 |
157 | | Parameters | Values |
158 | | ---------- | ------------------------------------------------------------------------------------------------------------------------- |
159 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` (typically a `Number` in milliseconds) |
160 | | `` | An optional `String` to specify the units of `` (typically `'seconds'`, `'minutes'`, `'hours'`...) |
161 |
162 | **Examples**
163 |
164 | ```hbs
165 | {{dayjs-duration 100}}
166 | {{! duration object }}
167 | {{dayjs-duration 24 'hours'}}
168 | {{! duration object }}
169 | ```
170 |
171 | ### dayjs-duration-humanize
172 |
173 | ```hbs
174 | {{dayjs-duration-humanize []}}
175 | ```
176 |
177 | | Parameters | Values |
178 | | ---------- | ------------------------------------------------------------------------------------------------------------------------- |
179 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` (typically a `Number` in milliseconds) |
180 | | `` | An optional `String` to specify the units of `` (typically `'seconds'`, `'minutes'`, `'hours'`...) |
181 |
182 | **Examples**
183 |
184 | ```hbs
185 | {{dayjs-duration-humanize 100}}
186 | {{! a few seconds }}
187 | {{dayjs-duration-humanize 24 'hours'}}
188 | {{! a day }}
189 | ```
190 |
191 | ### dayjs-calendar
192 |
193 | ```hbs
194 | {{dayjs-calendar []}}
195 | ```
196 |
197 | | Parameters | Values |
198 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
199 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
200 | | `` | An optional [output format hash](#/docs/#/displaying/calendar-time), defaults to `{}` |
201 |
202 | **Examples**
203 |
204 | ```hbs
205 | {{! in March 2021 at time of writing }}
206 | {{dayjs-from-now '2021-03-19'}}
207 | {{! 2 days ago }}
208 | {{dayjs-calendar '2021-03-20'}}
209 | {{! Yesterday at 12:00 AM }}
210 | ```
211 |
212 | ### dayjs-diff
213 |
214 | ```hbs
215 | {{dayjs-diff [precision='milliseconds' [float=false]]}}
216 | ```
217 |
218 | | Parameters | Values |
219 | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
220 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
221 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
222 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
223 | | `float` | An optional `Boolean` to get the floating point result, rather than the integer value |
224 |
225 | Returns the difference in `precision` units between `` and `` with floating point accuracy if `float` is `true`. See [`dayjs#diff`](#/docs/#/displaying/difference/).
226 |
227 | **Examples**
228 |
229 | ```hbs
230 | {{dayjs-diff '2018-01-25' '2018-01-26'}}
231 | {{! 86400000 }}
232 | {{dayjs-diff '2018-01-25' '2018-01-26' precision='years' float=true}}
233 | {{! 0.0026881720430107525 }}
234 | ```
235 |
236 | ### dayjs-add
237 |
238 | ```hbs
239 | {{dayjs-add [precision='milliseconds']}}
240 | ```
241 |
242 | | Parameters | Values |
243 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
244 | | `` | An optional value [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). Defaults to value of `dayjs()` |
245 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` that is the amount of the `precision` you want to `add` to the `date` provided |
246 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
247 |
248 | Mutates the original dayjs by adding time. See [`dayjs#add`](#/docs/#/manipulating/add/).
249 |
250 | **Examples**
251 |
252 | ```hbs
253 | {{! Add 6 days to a date }}
254 | {{dayjs-add '10-19-2019' 6 precision='days'}}
255 |
256 | {{! Add 6 days to a date }}
257 | {{dayjs-add '10-19-2019' (dayjs-duration (hash days=6))}}
258 |
259 | {{! Print a date 6 days from now }}
260 | {{dayjs-add 6 precision='days'}}
261 | ```
262 |
263 | ### dayjs-subtract
264 |
265 | ```hbs
266 | {{dayjs-subtract [precision='milliseconds']}}
267 | ```
268 |
269 | | Parameters | Values |
270 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
271 | | `` | An optional value [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). Defaults to value of `dayjs()` |
272 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` that is the amount of the `precision` you want to `subtract` from the `date` provided |
273 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
274 |
275 | Mutates the original dayjs by removing time. See [`dayjs#subtract`](#/docs/#/manipulating/subtract/).
276 |
277 | **Examples**
278 |
279 | ```hbs
280 | {{! Remove 6 days from a date }}
281 | {{dayjs-subtract '10-19-2019' 6 precision='days'}}
282 |
283 | {{! Remove 6 days from a date }}
284 | {{dayjs-subtract '10-19-2019' (dayjs-duration (hash days=6))}}
285 |
286 | {{! Print a date 6 days earlier }}
287 | {{dayjs-subtract 6 precision='days'}}
288 | ```
289 |
290 | ### dayjs-is-before / dayjs-is-after / dayjs-is-same / dayjs-is-same-or-before / dayjs-is-same-or-after
291 |
292 | ```hbs
293 | {{dayjs-is-before [] [precision='milliseconds']}}
294 | {{dayjs-is-after [] [precision='milliseconds']}}
295 | {{dayjs-is-same [] [precision='milliseconds']}}
296 | {{dayjs-is-same-or-before [] [precision='milliseconds']}}
297 | {{dayjs-is-same-or-after [] [precision='milliseconds']}}
298 | ```
299 |
300 | | Parameters | Values |
301 | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
302 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
303 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). If not given, `` becomes now and `` becomes `` |
304 | | `precision` | An optional `String` unit of comparison [precision](#/docs/#/query/isBefore), defaults to `'milliseconds'` |
305 |
306 | Returns a `Boolean` that indicates if `` is respectively before/after/the same/same or before/ same or after `` to the `precision` level. See [`dayjs#queries`](#/docs/#/query/).
307 |
308 | **Examples**
309 |
310 | ```hbs
311 | {{dayjs-is-before '2995-12-25'}}
312 | {{! false }}
313 | {{dayjs-is-before '2018-01-25' '2018-01-26' precision='years'}}
314 | {{! false }}
315 | {{dayjs-is-same-or-after '2018-01-25' '2018-01-26' precision='years'}}
316 | {{! true }}
317 | ```
318 |
319 | ### is-between
320 |
321 | ```hbs
322 | {{dayjs-is-between [] [precision='year' inclusivity='[)']}}
323 | ```
324 |
325 | | Parameters | Values |
326 | | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
327 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
328 | | `` | A boundary value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
329 | | `` | An optional boundary value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). If not given `` is assigned now, `` is assigned `` and `` is assigned ``. |
330 | | `precision` | An optional `String` unit of comparison [precision](#/docs/#/query/is-between), defaults to `'milliseconds'` |
331 | | `inclusivity` | An optional `String` indicating inclusivity of the boundaries, defaults to `()` |
332 |
333 | Returns a `Boolean` that indicates if `` is between `` and `` to the `precision` level and with boundary inclusions specified by `inclusivity`. See [`dayjs#is-between`](#/docs/#/query/is-between).
334 |
335 | **Examples**
336 |
337 | ```hbs
338 | {{dayjs-is-between '1995-12-25' '2995-12-25'}}
339 | {{! true }}
340 | {{dayjs-is-between
341 | '1995-12-25'
342 | '1995-12-25'
343 | '2995-12-25'
344 | precision='years'
345 | inclusivity='()'
346 | }}
347 | {{! true }}
348 | ```
349 |
350 | ### now
351 |
352 | ```hbs
353 | {{now}}
354 | {{dayjs-format (now) 'MM-DD-YYYY'}}
355 | ```
356 |
357 | Returns the present Dayjs.
358 |
359 | **Examples**
360 |
361 | ```hbs
362 | {{now}}
363 | {{! Current Date Time }}
364 | {{now interval=1000}}
365 | {{! }}
366 | ```
367 |
368 | ### unix
369 |
370 | ```hbs
371 | {{unix }}
372 | ```
373 |
374 | | Parameters | Values |
375 | | ------------- | ---------------------------------------------------------------------------------------------------------------- |
376 | | `` | An integer `Number` value representing the number of milliseconds since the Unix Epoch (January 1 1970 12AM UTC) |
377 |
378 | Returns a Dayjs corresponding to the ``.
379 |
380 | **Examples**
381 |
382 | ```hbs
383 | {{unix 1548381600000}}
384 | {{! Thursday, 26 January 2023 19:11:32 }}
385 | {{! Warning: The passing argument must be a number }}
386 | {{unix '1548381600000'}}
387 | {{! Invalid date }}
388 | ```
389 |
390 | ### Common optional named arguments
391 |
392 | All helpers accept the following optional named arguments (even though they are not always applicable):
393 |
394 | | Parameters | Values |
395 | | ---------- | -------------------------------------------------------------------------------------------- |
396 | | `locale` | An optional `String` [locale](#/docs/#/i18n/), to override the default global `dayjs.locale` |
397 | | `interval` | An optional interval `Number` of milliseconds when the helper should be recomputed |
398 |
399 | **Examples**
400 |
401 | ```hbs
402 | {{now interval=1000}}
403 | {{! }}
404 | {{dayjs-is-before (now) '2018-01-26' interval=60000}}
405 | {{! if this was true initially, it will always be true despite interval }}
406 | ```
407 |
408 | ### Configure default runtime locale/timeZone
409 |
410 | #### Globally set locale
411 |
412 | ```js
413 | import Controller from '@ember/controller';
414 | import { action } from '@ember/object';
415 | import { inject as service } from '@ember/service';
416 |
417 | export default class ApplicationController extends Controller {
418 | @service dayjs;
419 |
420 | @action
421 | changeLanguage(locale) {
422 | this.dayjs.setLocale(locale); // tr
423 | }
424 | }
425 | ```
426 |
427 | #### Globally set time zone
428 |
429 | ```js
430 | import Controller from '@ember/controller';
431 | import { action } from '@ember/object';
432 | import { inject as service } from '@ember/service';
433 |
434 | export default class ApplicationController extends Controller {
435 | @service dayjs;
436 |
437 | @action
438 | changeTimeZone(timeZone) {
439 | this.dayjs.setTimeZone(timeZone); // 'America/Los_Angeles'
440 | }
441 | }
442 | ```
443 |
444 | #### Reset time zone
445 |
446 | ```js
447 | import Controller from '@ember/controller';
448 | import { action } from '@ember/object';
449 | import { inject as service } from '@ember/service';
450 |
451 | export default class ApplicationController extends Controller {
452 | @service dayjs;
453 |
454 | @action
455 | resetTimezone() {
456 | this.dayjs.resetTimezone();
457 | }
458 | }
459 | ```
460 |
461 | ## Contributing
462 |
463 | See the [Contributing](CONTRIBUTING.md) guide for details.
464 |
465 | ## License
466 |
467 | This project is licensed under the [MIT License](LICENSE.md).
468 |
--------------------------------------------------------------------------------
/ember-dayjs/README.md:
--------------------------------------------------------------------------------
1 | # ember-dayjs
2 |
3 | [day.js](https://day.js.org/) template helpers and a service for Ember.
4 | Nearly drop-in replacement for [ember-moment](https://github.com/stefanpenner/ember-moment).
5 | Just replace all `moment-` with `dayjs-` and try.
6 |
7 | ## Compatibility
8 |
9 | - Ember.js v3.28 or above
10 | - Embroider or ember-auto-import v2
11 |
12 | ## Installation
13 |
14 | ```
15 | ember install ember-dayjs
16 | ```
17 |
18 | ## Usage
19 |
20 | ## Helpers
21 |
22 | ### dayjs
23 |
24 | ```hbs
25 | {{dayjs }}
26 | ```
27 |
28 | | Parameters | Values |
29 | | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
30 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
31 |
32 | Returns a Dayjs.
33 |
34 | ```hbs
35 | {{utc }}
36 | {{utc}}
37 | ```
38 |
39 | | Parameters | Values |
40 | | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/plugin/utc#dayjsutc-dayjsutcdatetype-string--number--date--dayjs-format-string) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
42 |
43 | Returns a Dayjs with [UTC mode](http://dayjs.com/docs/#/parsing/utc/) set.
44 |
45 | **Example**
46 |
47 | ```hbs
48 | {{utc '2001-10-31T08:24:56'}}
49 | {{! Wed Oct 31 2001 08:24:56 GMT+0000 }}
50 | {{utc}}
51 | {{! current time utc, like Mon Feb 12 2018 20:33:08 GMT+0000 }}
52 | {{utc (dayjs '2018-01-01T00:00:00+01:00' 'YYYY-MM-DD HH:mm:ssZ')}}
53 | {{! Sun Dec 31 2017 23:00:00 GMT+0000 }}
54 | ```
55 |
56 | ### dayjs-format
57 |
58 | ```hbs
59 | {{dayjs-format [outputFormat=dayjs.defaultFormat] [] []}}
60 | ```
61 |
62 | | Parameters | Values |
63 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
64 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
65 | | `outputFormat` | An optional date/time `String` [output format](https://day.js.org/docs/en/display/format), defaults to `dayjs.defaultFormat` |
66 | | `inputFormat` | An optional named argument for date/time String input format |
67 | | `advanced` | Pass `true` to be able to use [advanced format](https://day.js.org/docs/en/plugin/advanced-format) |
68 |
69 | **Example**
70 |
71 | ```hbs
72 | {{dayjs-format '12-1995-25' 'MM/DD/YYYY' inputFormat='MM-YYYY-DD'}}
73 | {{! 25/12/1995 }}
74 | ```
75 |
76 | ### timezone
77 |
78 | ```hbs
79 | {{dayjs-tz [timeZone]}}
80 | ```
81 |
82 | | Parameters | Values |
83 | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
84 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
85 | | `` | Optional: Time Zone Name Ex: America/Los_Angeles |
86 |
87 | Returns a Dayjs corresponding to the ``.
88 |
89 | **Examples**
90 |
91 | ```hbs
92 | {{dayjs-tz '2014-06-01 12:00' 'America/Los_Angeles'}}
93 | ```
94 |
95 | ### dayjs-from / dayjs-from-now
96 |
97 | ```hbs
98 | {{dayjs-from [] [hideAffix=false]}}
99 | {{dayjs-from-now [hideAffix=false]}}
100 | ```
101 |
102 | | Parameters | Values |
103 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
104 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
105 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...), defaults to now |
106 | | `hideAffix` | An optional `Boolean` to hide the relative prefix/suffix not. |
107 |
108 | Returns the time between `` and `` relative to ``. See [`dayjs#from`](#/docs/#/displaying/from/).
109 |
110 | **Examples**
111 |
112 | ```hbs
113 | {{! in January 2018 at time of writing }}
114 | {{dayjs-from '2995-12-25'}}
115 | {{! in 978 years }}
116 | {{dayjs-from-now '2995-12-25'}}
117 | {{! in 978 years }}
118 | {{dayjs-from '1995-12-25' '2995-12-25' hideAffix=true}}
119 | {{! 1000 years }}
120 | ```
121 |
122 | ### dayjs-to / dayjs-to-now
123 |
124 | ```hbs
125 | {{dayjs-to [] [hideAffix=false]}}
126 | {{dayjs-to-now [hideAffix=false]}}
127 | ```
128 |
129 | | Parameters | Values |
130 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
131 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
132 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...), defaults to now |
133 | | `hideAffix` | An optional `Boolean` to hide the relative prefix/suffix or not. |
134 |
135 | Returns the time between `` and `` relative to ``. See [`dayjs#to`](#/docs/#/displaying/to/).
136 |
137 | _Note that `dayjs-to-now` is just a more verbose `dayjs-to` without `dateB`. You don't need to use it anymore._
138 |
139 | **Examples**
140 |
141 | ```hbs
142 | {{! in January 2018 at time of writing }}
143 | {{dayjs-to '2995-12-25'}}
144 | {{! 978 years ago }}
145 | {{dayjs-to '1995-12-25' '2995-12-25'}}
146 | {{! in 1000 years }}
147 | {{dayjs-to-now '1995-12-25' hideAffix=true}}
148 | {{! 22 years }}
149 | ```
150 |
151 | ### dayjs-duration
152 |
153 | ```hbs
154 | {{dayjs-duration []}}
155 | ```
156 |
157 | | Parameters | Values |
158 | | ---------- | ------------------------------------------------------------------------------------------------------------------------- |
159 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` (typically a `Number` in milliseconds) |
160 | | `` | An optional `String` to specify the units of `` (typically `'seconds'`, `'minutes'`, `'hours'`...) |
161 |
162 | **Examples**
163 |
164 | ```hbs
165 | {{dayjs-duration 100}}
166 | {{! duration object }}
167 | {{dayjs-duration 24 'hours'}}
168 | {{! duration object }}
169 | ```
170 |
171 | ### dayjs-duration-humanize
172 |
173 | ```hbs
174 | {{dayjs-duration-humanize []}}
175 | ```
176 |
177 | | Parameters | Values |
178 | | ---------- | ------------------------------------------------------------------------------------------------------------------------- |
179 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` (typically a `Number` in milliseconds) |
180 | | `` | An optional `String` to specify the units of `` (typically `'seconds'`, `'minutes'`, `'hours'`...) |
181 |
182 | **Examples**
183 |
184 | ```hbs
185 | {{dayjs-duration-humanize 100}}
186 | {{! a few seconds }}
187 | {{dayjs-duration-humanize 24 'hours'}}
188 | {{! a day }}
189 | ```
190 |
191 | ### dayjs-calendar
192 |
193 | ```hbs
194 | {{dayjs-calendar []}}
195 | ```
196 |
197 | | Parameters | Values |
198 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
199 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
200 | | `` | An optional [output format hash](#/docs/#/displaying/calendar-time), defaults to `{}` |
201 |
202 | **Examples**
203 |
204 | ```hbs
205 | {{! in March 2021 at time of writing }}
206 | {{dayjs-from-now '2021-03-19'}}
207 | {{! 2 days ago }}
208 | {{dayjs-calendar '2021-03-20'}}
209 | {{! Yesterday at 12:00 AM }}
210 | ```
211 |
212 | ### dayjs-diff
213 |
214 | ```hbs
215 | {{dayjs-diff [precision='milliseconds' [float=false]]}}
216 | ```
217 |
218 | | Parameters | Values |
219 | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
220 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
221 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
222 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
223 | | `float` | An optional `Boolean` to get the floating point result, rather than the integer value |
224 |
225 | Returns the difference in `precision` units between `` and `` with floating point accuracy if `float` is `true`. See [`dayjs#diff`](#/docs/#/displaying/difference/).
226 |
227 | **Examples**
228 |
229 | ```hbs
230 | {{dayjs-diff '2018-01-25' '2018-01-26'}}
231 | {{! 86400000 }}
232 | {{dayjs-diff '2018-01-25' '2018-01-26' precision='years' float=true}}
233 | {{! 0.0026881720430107525 }}
234 | ```
235 |
236 | ### dayjs-add
237 |
238 | ```hbs
239 | {{dayjs-add [precision='milliseconds']}}
240 | ```
241 |
242 | | Parameters | Values |
243 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
244 | | `` | An optional value [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). Defaults to value of `dayjs()` |
245 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` that is the amount of the `precision` you want to `add` to the `date` provided |
246 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
247 |
248 | Mutates the original dayjs by adding time. See [`dayjs#add`](#/docs/#/manipulating/add/).
249 |
250 | **Examples**
251 |
252 | ```hbs
253 | {{! Add 6 days to a date }}
254 | {{dayjs-add '10-19-2019' 6 precision='days'}}
255 |
256 | {{! Add 6 days to a date }}
257 | {{dayjs-add '10-19-2019' (dayjs-duration (hash days=6))}}
258 |
259 | {{! Print a date 6 days from now }}
260 | {{dayjs-add 6 precision='days'}}
261 | ```
262 |
263 | ### dayjs-subtract
264 |
265 | ```hbs
266 | {{dayjs-subtract [precision='milliseconds']}}
267 | ```
268 |
269 | | Parameters | Values |
270 | | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
271 | | `` | An optional value [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). Defaults to value of `dayjs()` |
272 | | `` | Any value(s) [interpretable as a duration](#/docs/#/durations/creating) by `dayjs` that is the amount of the `precision` you want to `subtract` from the `date` provided |
273 | | `precision` | An optional [unit of measurement](#/docs/#/displaying/difference), defaults to `'milliseconds'` |
274 |
275 | Mutates the original dayjs by removing time. See [`dayjs#subtract`](#/docs/#/manipulating/subtract/).
276 |
277 | **Examples**
278 |
279 | ```hbs
280 | {{! Remove 6 days from a date }}
281 | {{dayjs-subtract '10-19-2019' 6 precision='days'}}
282 |
283 | {{! Remove 6 days from a date }}
284 | {{dayjs-subtract '10-19-2019' (dayjs-duration (hash days=6))}}
285 |
286 | {{! Print a date 6 days earlier }}
287 | {{dayjs-subtract 6 precision='days'}}
288 | ```
289 |
290 | ### dayjs-is-before / dayjs-is-after / dayjs-is-same / dayjs-is-same-or-before / dayjs-is-same-or-after
291 |
292 | ```hbs
293 | {{dayjs-is-before [] [precision='milliseconds']}}
294 | {{dayjs-is-after [] [precision='milliseconds']}}
295 | {{dayjs-is-same [] [precision='milliseconds']}}
296 | {{dayjs-is-same-or-before [] [precision='milliseconds']}}
297 | {{dayjs-is-same-or-after [] [precision='milliseconds']}}
298 | ```
299 |
300 | | Parameters | Values |
301 | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
302 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
303 | | `` | An optional value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). If not given, `` becomes now and `` becomes `` |
304 | | `precision` | An optional `String` unit of comparison [precision](#/docs/#/query/isBefore), defaults to `'milliseconds'` |
305 |
306 | Returns a `Boolean` that indicates if `` is respectively before/after/the same/same or before/ same or after `` to the `precision` level. See [`dayjs#queries`](#/docs/#/query/).
307 |
308 | **Examples**
309 |
310 | ```hbs
311 | {{dayjs-is-before '2995-12-25'}}
312 | {{! false }}
313 | {{dayjs-is-before '2018-01-25' '2018-01-26' precision='years'}}
314 | {{! false }}
315 | {{dayjs-is-same-or-after '2018-01-25' '2018-01-26' precision='years'}}
316 | {{! true }}
317 | ```
318 |
319 | ### is-between
320 |
321 | ```hbs
322 | {{dayjs-is-between [] [precision='year' inclusivity='[)']}}
323 | ```
324 |
325 | | Parameters | Values |
326 | | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
327 | | `` | Any value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
328 | | `` | A boundary value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...) |
329 | | `` | An optional boundary value(s) [interpretable as a date/time](https://day.js.org/docs/en/parse/parse) by `dayjs` (a date `String` or a `Dayjs` or a `Date`...). If not given `` is assigned now, `` is assigned `` and `` is assigned ``. |
330 | | `precision` | An optional `String` unit of comparison [precision](#/docs/#/query/is-between), defaults to `'milliseconds'` |
331 | | `inclusivity` | An optional `String` indicating inclusivity of the boundaries, defaults to `()` |
332 |
333 | Returns a `Boolean` that indicates if `` is between `` and `` to the `precision` level and with boundary inclusions specified by `inclusivity`. See [`dayjs#is-between`](#/docs/#/query/is-between).
334 |
335 | **Examples**
336 |
337 | ```hbs
338 | {{dayjs-is-between '1995-12-25' '2995-12-25'}}
339 | {{! true }}
340 | {{dayjs-is-between
341 | '1995-12-25'
342 | '1995-12-25'
343 | '2995-12-25'
344 | precision='years'
345 | inclusivity='()'
346 | }}
347 | {{! true }}
348 | ```
349 |
350 | ### now
351 |
352 | ```hbs
353 | {{now}}
354 | {{dayjs-format (now) 'MM-DD-YYYY'}}
355 | ```
356 |
357 | Returns the present Dayjs.
358 |
359 | **Examples**
360 |
361 | ```hbs
362 | {{now}}
363 | {{! Current Date Time }}
364 | {{now interval=1000}}
365 | {{! }}
366 | ```
367 |
368 | ### unix
369 |
370 | ```hbs
371 | {{unix }}
372 | ```
373 |
374 | | Parameters | Values |
375 | | ------------- | ---------------------------------------------------------------------------------------------------------------- |
376 | | `` | An integer `Number` value representing the number of milliseconds since the Unix Epoch (January 1 1970 12AM UTC) |
377 |
378 | Returns a Dayjs corresponding to the ``.
379 |
380 | **Examples**
381 |
382 | ```hbs
383 | {{unix 1548381600000}}
384 | {{! Thursday, 26 January 2023 19:11:32 }}
385 | {{! Warning: The passing argument must be a number }}
386 | {{unix '1548381600000'}}
387 | {{! Invalid date }}
388 | ```
389 |
390 | ### Common optional named arguments
391 |
392 | All helpers accept the following optional named arguments (even though they are not always applicable):
393 |
394 | | Parameters | Values |
395 | | ---------- | -------------------------------------------------------------------------------------------- |
396 | | `locale` | An optional `String` [locale](#/docs/#/i18n/), to override the default global `dayjs.locale` |
397 | | `interval` | An optional interval `Number` of milliseconds when the helper should be recomputed |
398 |
399 | **Examples**
400 |
401 | ```hbs
402 | {{now interval=1000}}
403 | {{! }}
404 | {{dayjs-is-before (now) '2018-01-26' interval=60000}}
405 | {{! if this was true initially, it will always be true despite interval }}
406 | ```
407 |
408 | ### Configure default runtime locale/timeZone
409 |
410 | #### Globally set locale
411 |
412 | ```js
413 | import Controller from '@ember/controller';
414 | import { action } from '@ember/object';
415 | import { inject as service } from '@ember/service';
416 |
417 | export default class ApplicationController extends Controller {
418 | @service dayjs;
419 |
420 | @action
421 | changeLanguage(locale) {
422 | this.dayjs.setLocale(locale); // tr
423 | }
424 | }
425 | ```
426 |
427 | #### Globally set time zone
428 |
429 | ```js
430 | import Controller from '@ember/controller';
431 | import { action } from '@ember/object';
432 | import { inject as service } from '@ember/service';
433 |
434 | export default class ApplicationController extends Controller {
435 | @service dayjs;
436 |
437 | @action
438 | changeTimeZone(timeZone) {
439 | this.dayjs.setTimeZone(timeZone); // 'America/Los_Angeles'
440 | }
441 | }
442 | ```
443 |
444 | #### Reset time zone
445 |
446 | ```js
447 | import Controller from '@ember/controller';
448 | import { action } from '@ember/object';
449 | import { inject as service } from '@ember/service';
450 |
451 | export default class ApplicationController extends Controller {
452 | @service dayjs;
453 |
454 | @action
455 | resetTimezone() {
456 | this.dayjs.resetTimezone();
457 | }
458 | }
459 | ```
460 |
461 | ## Contributing
462 |
463 | See the [Contributing](CONTRIBUTING.md) guide for details.
464 |
465 | ## License
466 |
467 | This project is licensed under the [MIT License](LICENSE.md).
468 |
--------------------------------------------------------------------------------