Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from 'moment' to 'dayjs' #2219

Merged
merged 3 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"bootstrap": "^3.4.1",
"classnames": "^2.2.5",
"color-thief-browser": "^2.0.2",
"dayjs": "^1.8.28",
"expose-loader": "^0.7.5",
"flarum-webpack-config": "0.1.0-beta.10",
"jquery": "^3.4.1",
"jquery.hotkeys": "^0.1.0",
"lodash-es": "^4.17.14",
"m.attrs.bidi": "github:tobscure/m.attrs.bidi",
"mithril": "^0.2.8",
"moment": "^2.22.2",
"punycode": "^2.1.1",
"spin.js": "^3.1.0",
"webpack": "^4.43.0",
Expand Down
2 changes: 1 addition & 1 deletion js/src/common/helpers/fullTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @return {Object}
*/
export default function fullTime(time) {
const mo = moment(time);
const mo = dayjs(time);

const datetime = mo.format();
const full = mo.format('LLLL');
Expand Down
2 changes: 1 addition & 1 deletion js/src/common/helpers/humanTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import humanTimeUtil from '../utils/humanTime';
* @return {Object}
*/
export default function humanTime(time) {
const mo = moment(time);
const mo = dayjs(time);

const datetime = mo.format();
const full = mo.format('LLLL');
Expand Down
8 changes: 7 additions & 1 deletion js/src/common/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'expose-loader?$!expose-loader?jQuery!jquery';
import 'expose-loader?m!mithril';
import 'expose-loader?moment!moment';
import 'expose-loader?moment!expose-loader?dayjs!dayjs';
import 'expose-loader?m.bidi!m.attrs.bidi';
import 'bootstrap/js/affix';
import 'bootstrap/js/dropdown';
Expand All @@ -9,6 +9,12 @@ import 'bootstrap/js/tooltip';
import 'bootstrap/js/transition';
import 'jquery.hotkeys/jquery.hotkeys';

import relativeTime from 'dayjs/plugin/relativeTime';
import localizedFormat from 'dayjs/plugin/localizedFormat';

dayjs.extend(relativeTime);
dayjs.extend(localizedFormat);

import patchMithril from './utils/patchMithril';

patchMithril(window);
Expand Down
2 changes: 1 addition & 1 deletion js/src/common/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Object.assign(User.prototype, {
* @public
*/
isOnline() {
return this.lastSeenAt() > moment().subtract(5, 'minutes').toDate();
return dayjs().subtract(5, 'minutes').isBefore(this.lastSeenAt());
},

/**
Expand Down
8 changes: 4 additions & 4 deletions js/src/common/utils/humanTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @return {String}
*/
export default function humanTime(time) {
let m = moment(time);
const now = moment();
let m = dayjs(time);
askvortsov1 marked this conversation as resolved.
Show resolved Hide resolved
const now = dayjs();

// To prevent showing things like "in a few seconds" due to small offsets
// between client and server time, we always reset future dates to the
Expand All @@ -17,13 +17,13 @@ export default function humanTime(time) {
}

const day = 864e5;
const diff = m.diff(moment());
const diff = m.diff(dayjs());
let ago = null;

// If this date was more than a month ago, we'll show the name of the month
// in the string. If it wasn't this year, we'll show the year as well.
if (diff < -30 * day) {
if (m.year() === moment().year()) {
if (m.year() === dayjs().year()) {
ago = m.format('D MMM');
} else {
ago = m.format('ll');
Expand Down
2 changes: 1 addition & 1 deletion js/src/forum/components/PostStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class PostStream extends Component {
if (dt > 1000 * 60 * 60 * 24 * 4) {
content = [
<div className="PostStream-timeGap">
<span>{app.translator.trans('core.forum.post_stream.time_lapsed_text', { period: moment.duration(dt).humanize() })}</span>
<span>{app.translator.trans('core.forum.post_stream.time_lapsed_text', { period: dayjs(lastTime).to(time, true) })}</span>
</div>,
content,
];
Expand Down
2 changes: 1 addition & 1 deletion js/src/forum/components/PostStreamScrubber.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default class PostStreamScrubber extends Component {

this.index = index;
this.visible = visible;
this.description = period ? moment(period).format('MMMM YYYY') : '';
this.description = period ? dayjs(period).format('MMMM YYYY') : '';
}

config(isInitialized, context) {
Expand Down
4 changes: 0 additions & 4 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const config = require('flarum-webpack-config');
const webpack = require('webpack');
askvortsov1 marked this conversation as resolved.
Show resolved Hide resolved
const merge = require('webpack-merge');

module.exports = merge(config(), {
output: {
library: 'flarum.core'
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]
});