ember-moment
Advanced tools
Comparing version 0.1.0 to 0.2.0
import Ember from 'ember'; | ||
import moment from 'moment'; | ||
function ago(value, maybeInput, maybeOutput) { | ||
function ago(value, maybeInput) { | ||
var length = arguments.length; | ||
var input, output; | ||
var args = [value]; | ||
if (length === 1) { | ||
throw new TypeError('Invalid Number of arguments, expected atleast 1'); | ||
} else if (length === 2 ) { | ||
input = 'LLLL'; | ||
} else if (length > 3) { | ||
input = maybeInput; | ||
output = maybeOutput; | ||
args.push(maybeInput); | ||
} | ||
return window.moment(value, input).fromNow(); | ||
return moment.apply(this, args).fromNow(); | ||
} | ||
@@ -18,0 +16,0 @@ |
import Ember from 'ember'; | ||
import momentjs from 'moment'; | ||
function moment(value, maybeInput, maybeOutput) { | ||
function moment(value, maybeOutput, maybeInput) { | ||
var length = arguments.length; | ||
var input, output; | ||
var args = []; | ||
var output; | ||
if (length === 1) { | ||
throw new TypeError('Invalid Number of arguments, expected atleast 1'); | ||
} else if (length === 2 ) { | ||
input = 'LLLL'; | ||
} | ||
args.push(value); | ||
if (length === 2) { | ||
args.push('LLLL'); | ||
} else if (length > 3) { | ||
input = maybeInput; | ||
args.push(maybeInput); | ||
output = maybeOutput; | ||
} | ||
return window.moment(value, input).format(output); | ||
return momentjs.apply(this, args).format(output); | ||
} | ||
@@ -18,0 +24,0 @@ |
@@ -11,4 +11,4 @@ 'use strict'; | ||
afterInstall: function() { | ||
return this.addBowerPackageToProject('momentjs', '^2.8.3'); | ||
return this.addBowerPackageToProject('ember-cli-moment-shim'); | ||
} | ||
}; |
@@ -7,5 +7,5 @@ { | ||
"ember": "1.7.0", | ||
"ember-data": "1.0.0-beta.10", | ||
"ember-resolver": "~0.1.7", | ||
"loader": "stefanpenner/loader.js#1.0.1", | ||
"ember-cli-moment-shim": "jasonmit/ember-cli-moment-shim#0.0.2", | ||
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3", | ||
@@ -16,5 +16,8 @@ "ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", | ||
"ember-qunit-notifications": "0.0.4", | ||
"qunit": "~1.15.0", | ||
"momentjs": "~2.8.3" | ||
"moment": "~2.8.3", | ||
"qunit": "~1.15.0" | ||
}, | ||
"devDependencies": { | ||
"moment-timezone": "~0.2.2" | ||
} | ||
} |
@@ -20,2 +20,10 @@ /* global require, module */ | ||
app.import(app.bowerDirectory + '/ember-cli-moment-shim/moment-shim.js', { | ||
exports: { | ||
moment: ['default'] | ||
} | ||
}); | ||
app.import(app.bowerDirectory + '/moment-timezone/moment-timezone.js'); | ||
module.exports = app.toTree(); |
17
index.js
@@ -7,11 +7,20 @@ 'user strict'; | ||
name: 'ember-moment', | ||
blueprintsPath: function() { | ||
blueprintsPath: function blueprintsPath() { | ||
return path.join(__dirname, 'blueprints'); | ||
}, | ||
included: function(app) { | ||
included: function included(app) { | ||
this.app = app; | ||
this._super.included(app); | ||
this.app.import(app.bowerDirectory + '/momentjs/moment.js'); | ||
app.import(app.bowerDirectory + '/moment/moment.js'); | ||
app.import(app.bowerDirectory + '/ember-cli-moment-shim/moment-shim.js', { | ||
exports: { | ||
moment: ['default'] | ||
} | ||
}); | ||
} | ||
}; |
{ | ||
"name": "ember-moment", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Moment.js template helpers for ember", | ||
"directories": { | ||
@@ -36,4 +37,3 @@ "doc": "doc", | ||
"configPath": "tests/dummy/config" | ||
}, | ||
"dependencies": {} | ||
} | ||
} |
@@ -22,2 +22,14 @@ # Ember-moment | ||
## Computed Macro | ||
```js | ||
import { moment, ago } from 'ember-moment/computed'; | ||
export default Ember.Controller.extend({ | ||
date: new Date('2013-02-08T09:30:26'), | ||
shortDate: moment('date', 'MM/DD/YYYY') | ||
timeSince: ago('date', true) | ||
}); | ||
``` | ||
## Development | ||
@@ -24,0 +36,0 @@ |
import Ember from 'ember'; | ||
export default Ember.Route.extend({ | ||
model: function() { | ||
return { | ||
now: new Date(), | ||
lastHour: new Date(new Date().valueOf() - (60*60*1000)) | ||
}; | ||
setupController: function (controller, model) { | ||
this._super(controller, model); | ||
setInterval(function () { | ||
Ember.run(function () { | ||
controller.set('date', new Date()); | ||
}); | ||
}, 1000); | ||
} | ||
}); |
@@ -0,1 +1,2 @@ | ||
import date from './date'; | ||
import { | ||
@@ -10,10 +11,9 @@ ago | ||
test('one arg (date)', function() { | ||
equal(ago(new Date(0), FAKE_HANDLEBARS_CONTEXT), "45 years ago"); | ||
equal(ago(new Date(), FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
equal(ago(date(0), FAKE_HANDLEBARS_CONTEXT), "45 years ago"); | ||
equal(ago(date(), FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
}); | ||
test('two args (date, inputFormat)', function() { | ||
equal(ago(new Date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '45 years ago'); | ||
equal(ago(new Date(), 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
equal(ago(date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '45 years ago'); | ||
equal(ago(date(), 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
}); | ||
@@ -0,1 +1,2 @@ | ||
import date from './date'; | ||
import { | ||
@@ -10,14 +11,14 @@ moment | ||
test('one arg (date)', function() { | ||
equal(moment(new Date(0), FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:00:00-05:00'); | ||
equal(moment(new Date(60*60*24), FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:01:00-05:00'); | ||
equal(moment(date(0), FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:00:00-05:00'); | ||
equal(moment(date(60*60*24), FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:01:26-05:00'); | ||
}); | ||
test('two args (date, inputFormat)', function() { | ||
equal(moment(new Date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:00:00-05:00'); | ||
equal(moment(new Date(60*60*24), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:01:26-05:00'); | ||
test('two args (date, outputFormat)', function() { | ||
equal(moment(date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:00:00-05:00'); | ||
equal(moment(date(60*60*24), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '1969-12-31T19:01:26-05:00'); | ||
}); | ||
test('three args (date, inputFormat, outputFormat)', function() { | ||
equal(moment(new Date(0), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(moment(new Date(60*60*24), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:01 PM'); | ||
test('three args (date, outputFormat, inputFormat)', function() { | ||
equal(moment(date(0), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(moment(date(60*60*24), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:01 PM'); | ||
}); |
Sorry, the diff of this file is not supported yet
22815
56
456
52