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

fixed moment date parsing deprecations #140

Merged
merged 1 commit into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 25 additions & 17 deletions app/validators/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,47 @@ const {
* @extends Base
*/
export default Base.extend({

_parseDate(dateStr, format) {
if (dateStr === 'now' || isEmpty(dateStr)) {
return moment();
} else {
return format ? moment(dateStr, format) : moment(new Date(dateStr));
}
},

validate(value, options) {
var errorFormat = options.errorFormat || 'MMM Do, YYYY';
var now = moment();
var date = moment(value);
let {format, before, after} = options;

if (options.allowBlank && isEmpty(value)) {
return true;
}

let date = this._parseDate(value, format);

if (!date.isValid()) {
return this.createErrorMessage('date', value, options);
}

if (options.format && !moment(value, options.format, true).isValid()) {
if (format && !moment(value, format, true).isValid()) {
return this.createErrorMessage('wrongDateFormat', value, options);
}

if (options.before === 'now') {
options.before = now;
}

if (options.after === 'now') {
options.after = now;
}

if (options.before && (moment(options.before) < date)) {
options.before = moment(options.before).format(errorFormat);
return this.createErrorMessage('before', value, options);
if (before) {
before = this._parseDate(before, format);
if (before < date) {
options.before = before.format(errorFormat);
return this.createErrorMessage('before', value, options);
}
}

if (options.after && (moment(options.after) > date)) {
options.after = moment(options.after).format(errorFormat);
return this.createErrorMessage('after', value, options);
if (after) {
after = this._parseDate(after, format);
if (after > date) {
options.after = after.format(errorFormat);
return this.createErrorMessage('after', value, options);
}
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

var App;
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/resolver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Resolver from 'ember/resolver';
import Resolver from 'ember-resolver';
import config from '../../config/environment';

var resolver = Resolver.create();
Expand Down