diff --git a/client/modules/IDE/components/SketchList.jsx b/client/modules/IDE/components/SketchList.jsx index 0bdef4c4..75a9b474 100644 --- a/client/modules/IDE/components/SketchList.jsx +++ b/client/modules/IDE/components/SketchList.jsx @@ -1,13 +1,13 @@ +import format from 'date-fns/format'; import PropTypes from 'prop-types'; import React from 'react'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -import moment from 'moment'; -import { Link, browserHistory } from 'react-router'; -import InlineSVG from 'react-inlinesvg'; import { Helmet } from 'react-helmet'; -import * as SketchActions from '../actions/projects'; +import InlineSVG from 'react-inlinesvg'; +import { connect } from 'react-redux'; +import { browserHistory, Link } from 'react-router'; +import { bindActionCreators } from 'redux'; import * as ProjectActions from '../actions/project'; +import * as SketchActions from '../actions/projects'; import * as ToastActions from '../actions/toast'; const trashCan = require('../../../images/trash-can.svg'); @@ -73,8 +73,8 @@ class SketchList extends React.Component { })()} {sketch.name} - {moment(sketch.createdAt).format('MMM D, YYYY h:mm A')} - {moment(sketch.updatedAt).format('MMM D, YYYY h:mm A')} + {format(new Date(sketch.createdAt), 'MMM D, YYYY h:mm A')} + {format(new Date(sketch.updatedAt), 'MMM D, YYYY h:mm A')} )} } diff --git a/client/modules/IDE/components/Timer.jsx b/client/modules/IDE/components/Timer.jsx index dacb96cd..25e4b247 100644 --- a/client/modules/IDE/components/Timer.jsx +++ b/client/modules/IDE/components/Timer.jsx @@ -1,7 +1,8 @@ +import classNames from 'classnames'; +import differenceInMilliseconds from 'date-fns/difference_in_milliseconds'; +import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; import PropTypes from 'prop-types'; import React from 'react'; -import moment from 'moment'; -import classNames from 'classnames'; class Timer extends React.Component { constructor(props) { @@ -20,16 +21,19 @@ class Timer extends React.Component { } showSavedTime() { - if (Math.abs(moment().diff(this.props.projectSavedTime)) < 10000) { + const now = new Date(); + if (Math.abs(differenceInMilliseconds(now, this.props.projectSavedTime) < 10000)) { return 'Saved: just now'; - } else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 20000) { + } else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 20000) { return 'Saved: 15 seconds ago'; - } else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 30000) { + } else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 30000) { return 'Saved: 25 seconds ago'; - } else if (Math.abs(moment().diff(this.props.projectSavedTime)) < 46000) { + } else if (differenceInMilliseconds(now, this.props.projectSavedTime) < 46000) { return 'Saved: 35 seconds ago'; } - return `Saved: ${moment(this.props.projectSavedTime).fromNow()}`; + return `Saved: ${distanceInWordsToNow(this.props.projectSavedTime, { + includeSeconds: true + })} ago`; } render() { diff --git a/package-lock.json b/package-lock.json index 6ed99d55..1a8b908f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3442,6 +3442,11 @@ "semver": "^5.5.0" } }, + "date-fns": { + "version": "1.30.1", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz", + "integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==" + }, "date-now": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", diff --git a/package.json b/package.json index 7ec248ef..ef5f892d 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "cors": "^2.8.5", "cross-env": "^5.2.0", "csslint": "^0.10.0", + "date-fns": "^1.30.1", "decomment": "^0.8.7", "dotenv": "^2.0.0", "dropzone": "^4.3.0", diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index 5c494d99..a281f725 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -1,6 +1,5 @@ import each from 'async/each'; -import moment from 'moment'; - +import isBefore from 'date-fns/is_before'; import Project from '../models/project'; import { resolvePathToFile } from '../utils/filePath'; import { deleteObjectsFromS3, getObjectKey } from './aws.controller'; @@ -56,7 +55,7 @@ function deleteMany(files, ids) { each(ids, (id, cb) => { if (files.id(id).url) { if (!process.env.S3_DATE - || (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(files.id(id).createdAt))) { + || (process.env.S3_DATE && isBefore(new Date(process.env.S3_DATE), new Date(files.id(id).createdAt)))) { const objectKey = getObjectKey(files.id(id).url); objectKeys.push(objectKey); } diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index c8899a38..9244c270 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -1,13 +1,14 @@ import archiver from 'archiver'; -import request from 'request'; -import moment from 'moment'; +import format from 'date-fns/format'; import isUrl from 'is-url'; -import slugify from 'slugify'; import jsdom, { serializeDocument } from 'jsdom'; -import { resolvePathToFile } from '../utils/filePath'; -import generateFileSystemSafeName from '../utils/generateFileSystemSafeName'; +import isBefore from 'date-fns/is_before'; +import request from 'request'; +import slugify from 'slugify'; import Project from '../models/project'; import User from '../models/user'; +import { resolvePathToFile } from '../utils/filePath'; +import generateFileSystemSafeName from '../utils/generateFileSystemSafeName'; import { deleteObjectsFromS3, getObjectKey } from './aws.controller'; export function createProject(req, res) { @@ -109,7 +110,7 @@ export function getProject(req, res) { function deleteFilesFromS3(files) { deleteObjectsFromS3(files.filter((file) => { if (file.url) { - if (!process.env.S3_DATE || (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(file.createdAt))) { + if (!process.env.S3_DATE || (process.env.S3_DATE && isBefore(new Date(process.env.S3_DATE), new Date(file.createdAt)))) { return true; } } @@ -291,7 +292,7 @@ function buildZip(project, req, res) { res.status(500).send({ error: err.message }); }); - const currentTime = moment().format('YYYY_MM_DD_HH_mm_ss'); + const currentTime = format(new Date(), 'YYYY_MM_DD_HH_mm_ss'); project.slug = slugify(project.name, '_'); res.attachment(`${generateFileSystemSafeName(project.slug)}_${currentTime}.zip`); zip.pipe(res);