sinankeskin / ember-dayjs Goto Github PK
View Code? Open in Web Editor NEWday.js template helpers and a service for Ember. Nearly drop-in replacement for ember-moment.
License: MIT License
day.js template helpers and a service for Ember. Nearly drop-in replacement for ember-moment.
License: MIT License
README states that the dayjs-format
usage is:
... and the example is given as:
However, this did not work for me. I had to add the outputFormat
keyword argument.
Without outputFormat
keyword argument:
With outputFormat
keyword argument:
I used to use the former one with ember-moment
.
Am I missing something?
Hi ! First things first thanks for creating this addon :)
I tried to install it but I think there is an issue with the webpack config. I can't load the locales because it doesn't find it. I have this message error on a the start of the app :
Here's my ember-cli-build
file:
// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const nodeSass = require('node-sass');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
const { Webpack } = require('@embroider/webpack');
const currentYear = new Date().getFullYear();
const isProduction = EmberApp.env() === 'production';
const isTest = EmberApp.env() === 'test';
module.exports = function (defaults) {
let app = new EmberApp(defaults, {
...
'ember-dayjs': {
locales: ['en-gb', 'fr', 'de', 'es'],
plugins: ['utc', 'localizedFormat']
},
autoImport: {
forbidEval: true,
webpack: {
plugins: [],
devtool: 'source-map',
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
legalComments: 'none',
sourcemap: !isProduction,
minify: isProduction,
css: true
})
]
}
}
},
// Autoprefixer options
autoprefixer: {
enabled: true,
cascade: true,
sourcemap: !isProduction
},
tests: isTest,
hinting: isTest
});
return require('@embroider/compat').compatBuild(app, Webpack, {
staticAddonTestSupportTrees: true,
staticAddonTrees: true,
staticHelpers: true,
staticModifiers: true,
staticComponents: true,
splitAtRoutes: [
'login',
],
packagerOptions: {
webpackConfig: {
devtool: 'source-map',
node: {
global: true
}
}
},
});
};
Do you have any ideas on how to fix or update this ? It would be nice maybe to pass the ember-cli-build config and set the dayjs plugin the same way you set the locale.
What do you think ? Has someone been already confronted to this issue ?
Thanks!
Hi there !
I was trying to use embroider on our ember applications: http://github.com/1024pix/pix
When using the 0.10.4 version of your addon, I had issues when building the application related to some typescript files:
ERROR in ../../../code/orga/node_modules/dayjs/plugin/advancedFormat.d.ts
Module build failed (from ../../../code/orga/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 1)
/code/orga/node_modules/dayjs/plugin/advancedFormat.d.ts: Missing semicolon. (3:7)
1 | import { PluginFunc } from 'dayjs'
2 |
> 3 | declare const plugin: PluginFunc
| ^
4 | export = plugin
5 |
at instantiate (/code/orga/node_modules/@babel/parser/lib/index.js:64:32)
at constructor (/code/orga/node_modules/@babel/parser/lib/index.js:361:12)
at Parser.raise (/code/orga/node_modules/@babel/parser/lib/index.js:3251:19)
at Parser.semicolon (/code/orga/node_modules/@babel/parser/lib/index.js:3622:10)
at Parser.parseExpressionStatement (/code/orga/node_modules/@babel/parser/lib/index.js:13075:10)
at Parser.parseStatementContent (/code/orga/node_modules/@babel/parser/lib/index.js:12679:19)
at Parser.parseStatementLike (/code/orga/node_modules/@babel/parser/lib/index.js:12535:17)
at Parser.parseModuleItem (/code/orga/node_modules/@babel/parser/lib/index.js:12519:17)
at Parser.parseBlockOrModuleBlockBody (/code/orga/node_modules/@babel/parser/lib/index.js:13106:36)
at Parser.parseBlockBody (/code/orga/node_modules/@babel/parser/lib/index.js:13099:10)
at Parser.parseProgram (/code/orga/node_modules/@babel/parser/lib/index.js:12433:10)
at Parser.parseTopLevel (/code/orga/node_modules/@babel/parser/lib/index.js:12423:25)
at Parser.parse (/code/orga/node_modules/@babel/parser/lib/index.js:14226:10)
at parse (/code/orga/node_modules/@babel/parser/lib/index.js:14268:38)
at parser (/code/orga/node_modules/@babel/core/lib/parser/index.js:41:34)
at parser.next (<anonymous>)
at normalizeFile (/code/orga/node_modules/@babel/core/lib/transformation/normalize-file.js:65:38)
at normalizeFile.next (<anonymous>)
at run (/code/orga/node_modules/@babel/core/lib/transformation/index.js:21:50)
at run.next (<anonymous>)
at transform (/code/orga/node_modules/@babel/core/lib/transform.js:22:41)
at transform.next (<anonymous>)
at step (/code/orga/node_modules/gensync/index.js:261:32)
at /code/orga/node_modules/gensync/index.js:273:13
at async.call.result.err.err (/code/orga/node_modules/gensync/index.js:223:11)
@ ./node_modules/ember-dayjs/node_modules/dayjs/plugin/ lazy ^\.\/.*$ namespace object ./advancedFormat.d.ts ./advancedFormat.d
@ ./node_modules/ember-dayjs/dist/services/dayjs.js 43:35-67
@ ./assets/pix-orga.js 2891:13-71
As typescript is not javascript this make senses. However the dist/services/dayjs.js
was different than the original services/dayjs.js
file. It seems to use dynamic import, await import(\
dayjs/plugin/${plugin}`);` and webpack try to bundle all files in the plugin dir, so it includes the typescript files.
I guess the addon/dist
folder was pushed on npm by mistake. Could you publish a new version to fix that?
Btw, I'm looking forward to use the new version with dynamic imports!
I'm having trouble with the {{unix}}
helper.
In the docs, the example shows
{{unix 1516586508}}
{{! Sun Jan 21 2018 21:01:48 GMT-0500 }}
But I get a different result:
{{unix 1516586508}}
{{! Sun, 18 Jan 1970 13:16:26 GMT }}
It's only until I multiply the input by 1000 that I get the desired output:
{{unix (multiply 1000 1516586508)}}
{{! Mon, 22 Jan 2018 02:01:48 GMT }}
Is there something I'm doing wrong?
Hi !
First, this is a very nice addon so thanks ! As specified on the README, I tried to cherry pick a locale within my ENV config :
// environment.js
module.exports = function (environment) {
let ENV = {
// ...
'ember-dayjs': {
locales: ['fr'],
plugins: ['duration'],
},
};
// ...
return ENV;
};
// routes/application.js
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ApplicationRoute extends Route {
@service dayjs;
beforeModel() {
this.dayjs.setLocale('fr');
}
}
After what I've got the following errors (even after restarting the app & reinstalling the addon) :
Error: Assertion Failed: fr locale not found. Please add to your app config in ember-cli-build.js file to include like:
'ember-dayjs': {
locales: ['fr'],
}
After that, usually you need to restart your application.
Did I miss something ?
Thanks for creating this drop-in replacement for moment? Been looking to move away.
Is something like adding Embroider support on the roadmap?
I'm hoping to use the UpdateLocale
plugin to tweak the English relativeTime
labels as described in the Day.js docs
I added the plugin to my ember-cli-build
config, expecting it to affect the injected service, e.g.,
@service dayjs;
beforeModel() {
this.day.js.updateLocale('en', {
relativeTime: { d: "yesterday"}
})
}
but the plugin doesn't seem to affect the service, i.e., this.dayjs.updateLocale
is undefined.
I'm probably approaching this wrong. How do I make these types of global changes to the config?
Hello, first of all thanks for your work.
We have a question.
It seems dayjs locale aren't set globally when we do : this.days.setLocale('fr')
. We have to do this.dayjs.self.locale('fr')
.
We saw this thrick when we use dayjs chartjs adapter in order to display the right language 1024pix/pix#6285 .
This is the way of ember-dayjs ? Or can we set dayjs locale when we define the this.days.setLocale('fr')
?
Thanks !
Hey, first of all thank you for this addon! It's very convenient and useful.
Unfortunately, I'm stumbled upon the issue with the next code:
{{dayjs-from-now @comment.posted locale='ru'}}
I do have this locale in a ember-cli-build.js:
'ember-dayjs': {
locales: ['ru'],
plugins: ['utc', 'relativeTime'],
}
However the string appears in English. How can I change to other locale?
P.S. I've tried to call 'setLocale' in ApplicationController - didn't have any effect.
Hi,
i'm trying ti use dayjs-duration-humanize
inside an app. it seem to missing
{{dayjs-duration-humanize tutorial.duration "minutes"}}
i've got this error
duration.js:1 Uncaught (in promise) TypeError: t(...).add(...).locale(...).fromNow is not a function
at y.humanize (duration.js:1:1)
at DayjsDurationHumanize.compute (dayjs-duration-humanize.js:12:1)
at index.js:5036:24
at deprecateMutationsInTrackingTransaction (validator.js:142:7)
at ClassicHelperManager.getValue (index.js:5035:7)
at manager.js:847:52
at reference.js:121:35
at track (validator.js:709:5)
at valueForRef (reference.js:120:21)
at Object.evaluate (runtime.js:3777:31)
i 've added this.dayjs.extend('relativeTime');
just before super in order to work.
import DayjsDurationHelper from './dayjs-duration';
export default class DayjsDurationHumanize extends DayjsDurationHelper {
compute(params, hash) {
this.dayjs.useLocale(hash.locale || this.dayjs.locale);
this.dayjs.extend('relativeTime');
return super
.compute(params, hash)
.locale(hash.locale || this.dayjs.locale)
.humanize();
}
}
Starting with 0.11.0 (the embroider v2 version of this addon), all dayjs locales and plugins end up in the final bundle
See my comments here: e4f8ca4#r117661519
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.