├── .bowerrc ├── .editorconfig ├── .ember-cli ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── Brocfile.js ├── LICENSE.md ├── README.md ├── addon ├── .gitkeep ├── helpers │ ├── date-and-time.js │ ├── day-of-the-week.js │ ├── month-and-day.js │ ├── month-and-year.js │ ├── time-ago-in-words.js │ ├── time-ahead-in-words.js │ ├── time-delta-in-words.js │ └── time-format.js └── utils │ ├── time-locale.js │ └── valid-args.js ├── app ├── .gitkeep └── initializers │ └── ember-cli-dates.js ├── blueprints └── ember-cli-dates │ └── index.js ├── bower.json ├── config └── environment.js ├── index.js ├── package.json ├── testem.json ├── tests ├── .jshintrc ├── dummy │ ├── .jshintrc │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ └── .gitkeep │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── router.js │ │ ├── routes │ │ │ ├── .gitkeep │ │ │ └── index.js │ │ ├── styles │ │ │ ├── .gitkeep │ │ │ └── app.css │ │ ├── templates │ │ │ ├── .gitkeep │ │ │ ├── application.hbs │ │ │ ├── components │ │ │ │ └── .gitkeep │ │ │ └── index.hbs │ │ └── views │ │ │ └── .gitkeep │ ├── config │ │ └── environment.js │ └── public │ │ ├── .gitkeep │ │ ├── crossdomain.xml │ │ └── robots.txt ├── helpers │ ├── resolver.js │ └── start-app.js ├── index.html ├── test-helper.js └── unit │ ├── .gitkeep │ └── helpers │ ├── date-and-time-test.js │ ├── day-of-the-week-test.js │ ├── month-and-day-test.js │ ├── month-and-year-test.js │ ├── time-ago-in-words-test.js │ ├── time-ahead-in-words-test.js │ ├── time-delta-in-words-test.js │ └── time-format-test.js └── vendor └── .gitkeep /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components", 3 | "analytics": false 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.js] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.hbs] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | [*.css] 25 | indent_style = space 26 | indent_size = 2 27 | 28 | [*.html] 29 | indent_style = space 30 | indent_size = 2 31 | 32 | [*.{diff,md}] 33 | trim_trailing_whitespace = false 34 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log 17 | testem.log 18 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "-Promise" 6 | ], 7 | "browser": true, 8 | "boss": true, 9 | "curly": true, 10 | "debug": false, 11 | "devel": true, 12 | "eqeqeq": true, 13 | "evil": true, 14 | "forin": false, 15 | "immed": false, 16 | "laxbreak": false, 17 | "newcap": true, 18 | "noarg": true, 19 | "noempty": false, 20 | "nonew": false, 21 | "nomen": false, 22 | "onevar": false, 23 | "plusplus": false, 24 | "regexp": false, 25 | "undef": true, 26 | "sub": true, 27 | "strict": false, 28 | "white": false, 29 | "eqnull": true, 30 | "esnext": true, 31 | "unused": true 32 | } 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | bower_components/ 2 | tests/ 3 | tmp/ 4 | 5 | .bowerrc 6 | .editorconfig 7 | .ember-cli 8 | .travis.yml 9 | .npmignore 10 | **/.gitkeep 11 | bower.json 12 | Brocfile.js 13 | testem.json 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | 4 | sudo: false 5 | 6 | node_js: 7 | - 'iojs' 8 | - '0.12' 9 | - '0.11' 10 | - '0.10' 11 | 12 | cache: 13 | directories: 14 | - node_modules 15 | 16 | before_install: 17 | - "npm config set spin false" 18 | - "npm install -g npm@^2" 19 | 20 | install: 21 | - npm install -g bower 22 | - npm install 23 | - bower install 24 | 25 | script: 26 | - npm test 27 | -------------------------------------------------------------------------------- /Brocfile.js: -------------------------------------------------------------------------------- 1 | /* jshint node: true */ 2 | /* global require, module */ 3 | 4 | var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 5 | 6 | var app = new EmberAddon(); 7 | 8 | // Use `app.import` to add additional libraries to the generated 9 | // output files. 10 | // 11 | // If you need to use different assets in different 12 | // environments, specify an object as the first parameter. That 13 | // object's keys should be the environment name and the values 14 | // should be the asset to use in that environment. 15 | // 16 | // If the library that you are including contains AMD or ES6 17 | // modules that you would like to import into your application 18 | // please specify an object with the list of modules as keys 19 | // along with the exports of each module as its value. 20 | 21 | // Import this locale to test dummy app 22 | app.import('bower_components/moment/locale/pt-br.js'); 23 | module.exports = app.toTree(); 24 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 John Otander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-dates [![Build](https://travis-ci.org/johnotander/ember-cli-dates.svg?branch=master)](https://travis-ci.org/johnotander/ember-cli-dates) [![Ember Observer Score](http://emberobserver.com/badges/ember-cli-dates.svg)](http://emberobserver.com/addons/ember-cli-dates) 2 | 3 | Ember date helpers with locale support. 4 | 5 | This addon includes `time-ago-in-words`, `time-ahead-in-words`, `time-delta-in-words`, 6 | `time-format`, `day-of-the-week`, `date-and-time`, `month-and-day`, `month-and-year`. 7 | It uses moment.js. 8 | 9 | ## Installation 10 | 11 | ``` 12 | ember install:addon ember-cli-dates 13 | ``` 14 | 15 | ## Usage 16 | 17 | Now, in your views/templates/components: 18 | 19 | ### Time Deltas 20 | 21 | #### Time Ago in Words 22 | 23 | ```hbs 24 | {{time-ago-in-words createdAt}} {{! => twelve days ago}} 25 | ``` 26 | 27 | #### Time Ahead in Words 28 | 29 | ```hbs 30 | {{time-ahead-in-words toBePublishedAt}} {{! => in 4 hours}} 31 | ``` 32 | 33 | #### Time Delta in Words 34 | 35 | ```hbs 36 | {{time-delta-in-words completedAt}} {{! => 7 minutes ago}} 37 | ``` 38 | 39 | #### Month and Day 40 | 41 | ```hbs 42 | {{month-and-day completedAt}} {{! => Jan 1st}} 43 | {{month-and-day completedAt}} {{! => jan 1º}} 44 | ``` 45 | 46 | #### Month and Year 47 | 48 | ```hbs 49 | {{month-and-year completedAt 'pt-br'}} {{! => Jan 2015}} 50 | ``` 51 | 52 | #### Date and Time 53 | 54 | ```hbs 55 | {{date-and-time publishedAt}} {{! January 1, 2014 12:00 AM}} 56 | {{date-and-time publishedAt 'pt-br'}} {{! 1 de janeiro de 2014 às 00:00}} 57 | ``` 58 | 59 | ### Custom Format 60 | 61 | ```hbs 62 | {{time-format updatedAt 'l'}} {{! => 10/9/2014}} 63 | ``` 64 | 65 | ### Day of the Week 66 | 67 | ```hbs 68 | {{day-of-the-week someDate}} {{! => Friday}} 69 | ``` 70 | 71 | ## Locale Support 72 | 73 | In order to add locale support, you need to import the locale file in your app's `Brocfile.js`: 74 | 75 | ```js 76 | app.import(app.bowerDirectory + '/moment/locale/pt-br.js'); 77 | ``` 78 | 79 | You then have the ability to specify any imported locale with: 80 | 81 | ```hbs 82 | {{time-format createdAt 'LLLL' 'pt-br'}} 83 | {{time-ahead-in-words nextHour 'pt-br'}} 84 | ``` 85 | 86 | ## License 87 | 88 | MIT 89 | 90 | ## Contributing 91 | 92 | 1. Fork it 93 | 2. npm install 94 | 3. bower install 95 | 4. Create your feature branch (`git checkout -b my-new-feature`) 96 | 5. Commit your changes (`git commit -am 'Add some feature'`) 97 | 6. Push to the branch (`git push origin my-new-feature`) 98 | 7. Create new Pull Request 99 | 100 | Crafted with <3 by [John Otander](http://johnotander.com)([@4lpine](https://twitter.com/4lpine)). 101 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/addon/.gitkeep -------------------------------------------------------------------------------- /addon/helpers/date-and-time.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import { timeFormat } from 'ember-cli-dates/helpers/time-format'; 3 | 4 | function dateAndTime(date, optionalLocale) { 5 | return timeFormat(date, 'LLL', optionalLocale); 6 | } 7 | 8 | export { dateAndTime }; 9 | 10 | export default Ember.Handlebars.makeBoundHelper(dateAndTime); 11 | -------------------------------------------------------------------------------- /addon/helpers/day-of-the-week.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function dayOfTheWeek(date, optionalLocale) { 7 | validArgs(arguments, 'day-of-the-week'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).format('dddd'); 14 | } 15 | 16 | export { dayOfTheWeek }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(dayOfTheWeek); 19 | -------------------------------------------------------------------------------- /addon/helpers/month-and-day.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function monthAndDay(date, optionalLocale) { 7 | validArgs(arguments, 'day-of-the-week'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).format('MMM Do'); 14 | } 15 | 16 | export { monthAndDay }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(monthAndDay); 19 | -------------------------------------------------------------------------------- /addon/helpers/month-and-year.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function monthAndYear(date, optionalLocale) { 7 | validArgs(arguments, 'day-of-the-week'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).format('MMM YYYY'); 14 | } 15 | 16 | export { monthAndYear }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(monthAndYear); 19 | -------------------------------------------------------------------------------- /addon/helpers/time-ago-in-words.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function timeAgoInWords(date, optionalLocale) { 7 | validArgs(arguments, 'time-ago-in-words'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).fromNow(); 14 | } 15 | 16 | export { timeAgoInWords }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(timeAgoInWords); 19 | -------------------------------------------------------------------------------- /addon/helpers/time-ahead-in-words.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function timeAheadInWords(date, optionalLocale) { 7 | validArgs(arguments, 'time-ahead-in-words'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).fromNow(); 14 | } 15 | 16 | export { timeAheadInWords }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(timeAheadInWords); 19 | -------------------------------------------------------------------------------- /addon/helpers/time-delta-in-words.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function timeDeltaInWords(date, optionalLocale) { 7 | validArgs(arguments, 'time-delta-in-words'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale); 12 | 13 | return moment(date).locale(locale).fromNow(); 14 | } 15 | 16 | export { timeDeltaInWords }; 17 | 18 | export default Ember.Handlebars.makeBoundHelper(timeDeltaInWords); 19 | -------------------------------------------------------------------------------- /addon/helpers/time-format.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | import timeLocale from 'ember-cli-dates/utils/time-locale'; 4 | import validArgs from 'ember-cli-dates/utils/valid-args'; 5 | 6 | function timeFormat(date, optionalFormat, optionalLocale) { 7 | validArgs(arguments, 'time-format'); 8 | 9 | if (Ember.isBlank(date)) { return ''; } 10 | 11 | var locale = timeLocale(optionalLocale), 12 | format = 'LL'; 13 | 14 | if (Ember.typeOf(optionalFormat) === 'string') { 15 | format = optionalFormat; 16 | } 17 | 18 | return moment(date).locale(locale).format(format); 19 | } 20 | 21 | export { timeFormat }; 22 | 23 | export default Ember.Handlebars.makeBoundHelper(timeFormat); 24 | -------------------------------------------------------------------------------- /addon/utils/time-locale.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import moment from 'moment'; 3 | 4 | export default function timeLocale(optionalLocale) { 5 | if (Ember.typeOf(optionalLocale) === 'string') { 6 | return optionalLocale; 7 | } 8 | 9 | return moment().locale(); 10 | } 11 | -------------------------------------------------------------------------------- /addon/utils/valid-args.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default function validArgs(args, helper) { 4 | if (Ember.isEmpty(args) || args.length === 1) { 5 | throw new Ember.Error('[ember-cli-dates:' + helper + '] Invalid number of arguments, expected at least 1'); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/app/.gitkeep -------------------------------------------------------------------------------- /app/initializers/ember-cli-dates.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import { timeFormat } from 'ember-cli-dates/helpers/time-format'; 3 | import { timeAgoInWords } from 'ember-cli-dates/helpers/time-ago-in-words'; 4 | import { dayOfTheWeek } from 'ember-cli-dates/helpers/day-of-the-week'; 5 | import { timeAheadInWords } from 'ember-cli-dates/helpers/time-ahead-in-words'; 6 | import { timeDeltaInWords } from 'ember-cli-dates/helpers/time-delta-in-words'; 7 | import { monthAndYear } from 'ember-cli-dates/helpers/month-and-year'; 8 | import { monthAndDay } from 'ember-cli-dates/helpers/month-and-day'; 9 | import { dateAndTime } from 'ember-cli-dates/helpers/date-and-time'; 10 | 11 | export var initialize = function(/* container, app */) { 12 | Ember.Handlebars.helper('time-format', timeFormat); 13 | Ember.Handlebars.helper('time-ago-in-words', timeAgoInWords); 14 | Ember.Handlebars.helper('day-of-the-week', dayOfTheWeek); 15 | Ember.Handlebars.helper('time-ahead-in-words', timeAheadInWords); 16 | Ember.Handlebars.helper('time-delta-in-words', timeDeltaInWords); 17 | Ember.Handlebars.helper('month-and-year', monthAndYear); 18 | Ember.Handlebars.helper('month-and-day', monthAndDay); 19 | Ember.Handlebars.helper('date-and-time', dateAndTime); 20 | }; 21 | 22 | export default { 23 | name: 'ember-cli-dates', 24 | initialize: initialize 25 | }; 26 | -------------------------------------------------------------------------------- /blueprints/ember-cli-dates/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | normalizeEntityName: function() { 5 | // this prevents an error when the entityName is 6 | // not specified (since that doesn't actually matter 7 | // to us 8 | }, 9 | 10 | afterInstall: function() { 11 | return this.addBowerPackageToProject('ember-cli-moment-shim', '0.0.3'); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-dates", 3 | "dependencies": { 4 | "jquery": "^1.11.1", 5 | "ember": "1.10.0", 6 | "ember-data": "1.0.0-beta.15", 7 | "ember-resolver": "~0.1.12", 8 | "loader.js": "ember-cli/loader.js#3.2.0", 9 | "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", 10 | "ember-cli-test-loader": "ember-cli-test-loader#0.1.3", 11 | "ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2", 12 | "ember-qunit": "0.2.8", 13 | "ember-qunit-notifications": "0.0.7", 14 | "qunit": "~1.17.1", 15 | "moment": "~2.9.0", 16 | "ember-cli-moment-shim": "~0.0.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return { }; 5 | }; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* jshint node: true */ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | 6 | module.exports = { 7 | name: 'ember-cli-dates', 8 | 9 | blueprintsPath: function() { 10 | return path.join(__dirname, 'blueprints'); 11 | }, 12 | 13 | included: function(app) { 14 | this._super.included(app); 15 | this.app.import(app.bowerDirectory + '/moment/moment.js'); 16 | this.app.import(app.bowerDirectory + '/ember-cli-moment-shim/moment-shim.js', { 17 | exports: { 18 | moment: ['default'] 19 | } 20 | }); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-dates", 3 | "version": "1.1.3", 4 | "description": "Ember date helpers with locale support.", 5 | "directories": { 6 | "doc": "doc", 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "start": "ember server", 11 | "build": "ember build", 12 | "test": "ember test" 13 | }, 14 | "repository": "https://github.com/johnotander/ember-cli-dates", 15 | "engines": { 16 | "node": ">= 0.10.0" 17 | }, 18 | "author": "John Otander", 19 | "license": "MIT", 20 | "devDependencies": { 21 | "broccoli-asset-rev": "^2.0.0", 22 | "ember-cli": "0.2.0", 23 | "ember-cli-app-version": "0.3.2", 24 | "ember-cli-babel": "^4.0.0", 25 | "ember-cli-content-security-policy": "0.3.0", 26 | "ember-cli-dependency-checker": "0.0.8", 27 | "ember-cli-htmlbars": "0.7.4", 28 | "ember-cli-ic-ajax": "0.1.1", 29 | "ember-cli-inject-live-reload": "^1.3.0", 30 | "ember-cli-qunit": "0.3.9", 31 | "ember-cli-uglify": "1.0.1", 32 | "ember-data": "1.0.0-beta.15", 33 | "ember-export-application-global": "^1.0.2" 34 | }, 35 | "keywords": [ 36 | "ember-addon", 37 | "ember-cli", 38 | "dates", 39 | "moment", 40 | "time-format", 41 | "time-ago-in-words", 42 | "time-ahead-in-words", 43 | "time-delta-in-words" 44 | ], 45 | "ember-addon": { 46 | "defaultBlueprint": "ember-cli-dates", 47 | "configPath": "tests/dummy/config" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /testem.json: -------------------------------------------------------------------------------- 1 | { 2 | "framework": "qunit", 3 | "test_page": "tests/index.html?hidepassed", 4 | "launch_in_ci": [ 5 | "PhantomJS" 6 | ], 7 | "launch_in_dev": [ 8 | "PhantomJS", 9 | "Chrome" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "location", 6 | "setTimeout", 7 | "$", 8 | "-Promise", 9 | "define", 10 | "console", 11 | "visit", 12 | "exists", 13 | "fillIn", 14 | "click", 15 | "keyEvent", 16 | "triggerEvent", 17 | "find", 18 | "findWithAssert", 19 | "wait", 20 | "DS", 21 | "andThen", 22 | "currentURL", 23 | "currentPath", 24 | "currentRouteName" 25 | ], 26 | "node": false, 27 | "browser": false, 28 | "boss": true, 29 | "curly": false, 30 | "debug": false, 31 | "devel": false, 32 | "eqeqeq": true, 33 | "evil": true, 34 | "forin": false, 35 | "immed": false, 36 | "laxbreak": false, 37 | "newcap": true, 38 | "noarg": true, 39 | "noempty": false, 40 | "nonew": false, 41 | "nomen": false, 42 | "onevar": false, 43 | "plusplus": false, 44 | "regexp": false, 45 | "undef": true, 46 | "sub": true, 47 | "strict": false, 48 | "white": false, 49 | "eqnull": true, 50 | "esnext": true 51 | } 52 | -------------------------------------------------------------------------------- /tests/dummy/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": { 3 | "document": true, 4 | "window": true, 5 | "-Promise": true, 6 | "moment": true 7 | }, 8 | "browser" : true, 9 | "boss" : true, 10 | "curly": true, 11 | "debug": false, 12 | "devel": true, 13 | "eqeqeq": true, 14 | "evil": true, 15 | "forin": false, 16 | "immed": false, 17 | "laxbreak": false, 18 | "newcap": true, 19 | "noarg": true, 20 | "noempty": false, 21 | "nonew": false, 22 | "nomen": false, 23 | "onevar": false, 24 | "plusplus": false, 25 | "regexp": false, 26 | "undef": true, 27 | "sub": true, 28 | "strict": false, 29 | "white": false, 30 | "eqnull": true, 31 | "esnext": true, 32 | "unused": true 33 | } 34 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Resolver from 'ember/resolver'; 3 | import loadInitializers from 'ember/load-initializers'; 4 | import config from './config/environment'; 5 | 6 | Ember.MODEL_FACTORY_INJECTIONS = true; 7 | 8 | var App = Ember.Application.extend({ 9 | modulePrefix: config.modulePrefix, 10 | podModulePrefix: config.podModulePrefix, 11 | Resolver: Resolver 12 | }); 13 | 14 | loadInitializers(App, config.modulePrefix); 15 | 16 | export default App; 17 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for 'head'}} 11 | 12 | 13 | 14 | 15 | {{content-for 'head-footer'}} 16 | 17 | 18 | {{content-for 'body'}} 19 | 20 | 21 | 22 | 23 | {{content-for 'body-footer'}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from './config/environment'; 3 | 4 | var Router = Ember.Router.extend({ 5 | location: config.locationType 6 | }); 7 | 8 | Router.map(function() { 9 | }); 10 | 11 | export default Router; 12 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/routes/index.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default Ember.Route.extend({ 4 | model: function() { 5 | return { 6 | now: new Date(), 7 | lastHour: new Date(new Date().valueOf() - (60*60*1000)), 8 | nextHour: new Date(new Date().valueOf() + (60*60*1000)) 9 | }; 10 | } 11 | }); 12 | -------------------------------------------------------------------------------- /tests/dummy/app/styles/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/styles/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 20px; 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/templates/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

ember-cli-dates

2 | 3 | {{outlet}} 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/index.hbs: -------------------------------------------------------------------------------- 1 |

time-format

2 |
3 | \{{time-format now}} 4 | {{time-format now}} 5 |
6 | \{{time-format now 'LLL'}} 7 | {{time-format now 'LLL'}} 8 |
9 | \{{time-format now 'LLLL' 'pt-br'}} 10 | {{time-format now 'LLLL' 'pt-br'}} 11 |
12 | 13 |

time-ago-in-words

14 |
15 | \{{time-ago-in-words lastHour}} 16 | {{time-ago-in-words lastHour}} 17 |
18 | \{{time-ago-in-words lastHour 'pt-br'}} 19 | {{time-ago-in-words lastHour 'pt-br'}} 20 |
21 |

day-of-the-week

22 |
23 | \{{day-of-the-week now}} 24 | {{day-of-the-week now}} 25 |
26 | \{{day-of-the-week now 'pt-br'}} 27 | {{day-of-the-week now 'pt-br'}} 28 |
29 | 30 |

time-ahead-in-words

31 |
32 | \{{time-ahead-in-words nextHour}} 33 | {{time-ahead-in-words nextHour}} 34 |
35 | \{{time-ahead-in-words nextHour 'pt-br'}} 36 | {{time-ahead-in-words nextHour 'pt-br'}} 37 |
38 | 39 |

time-delta-in-words

40 |
41 | \{{time-delta-in-words lastHour}} 42 | {{time-delta-in-words lastHour}} 43 |
44 | \{{time-delta-in-words lastHour 'pt-br'}} 45 | {{time-delta-in-words lastHour 'pt-br'}} 46 |
47 | -------------------------------------------------------------------------------- /tests/dummy/app/views/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/app/views/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | /* jshint node: true */ 2 | 3 | module.exports = function(environment) { 4 | var ENV = { 5 | modulePrefix: 'dummy', 6 | environment: environment, 7 | baseURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | } 14 | }, 15 | 16 | APP: { 17 | // Here you can pass flags/options to your application instance 18 | // when it is created 19 | } 20 | }; 21 | 22 | if (environment === 'development') { 23 | // ENV.APP.LOG_RESOLVER = true; 24 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 25 | // ENV.APP.LOG_TRANSITIONS = true; 26 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 27 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 28 | } 29 | 30 | if (environment === 'test') { 31 | // Testem prefers this... 32 | ENV.baseURL = '/'; 33 | ENV.locationType = 'none'; 34 | 35 | // keep test console output quieter 36 | ENV.APP.LOG_ACTIVE_GENERATION = false; 37 | ENV.APP.LOG_VIEW_LOOKUPS = false; 38 | 39 | ENV.APP.rootElement = '#ember-testing'; 40 | } 41 | 42 | if (environment === 'production') { 43 | 44 | } 45 | 46 | return ENV; 47 | }; 48 | -------------------------------------------------------------------------------- /tests/dummy/public/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/dummy/public/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /tests/helpers/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember/resolver'; 2 | import config from '../../config/environment'; 3 | 4 | var resolver = Resolver.create(); 5 | 6 | resolver.namespace = { 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix 9 | }; 10 | 11 | export default resolver; 12 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Application from '../../app'; 3 | import Router from '../../router'; 4 | import config from '../../config/environment'; 5 | 6 | export default function startApp(attrs) { 7 | var application; 8 | 9 | var attributes = Ember.merge({}, config.APP); 10 | attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; 11 | 12 | Ember.run(function() { 13 | application = Application.create(attributes); 14 | application.setupForTesting(); 15 | application.injectTestHelpers(); 16 | }); 17 | 18 | return application; 19 | } 20 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for 'head'}} 11 | {{content-for 'test-head'}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for 'head-footer'}} 18 | {{content-for 'test-head-footer'}} 19 | 20 | 21 | 22 | {{content-for 'body'}} 23 | {{content-for 'test-body'}} 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for 'body-footer'}} 31 | {{content-for 'test-body-footer'}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import resolver from './helpers/resolver'; 2 | import { 3 | setResolver 4 | } from 'ember-qunit'; 5 | 6 | setResolver(resolver); 7 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/helpers/date-and-time-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { dateAndTime } from 'ember-cli-dates/helpers/date-and-time'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('DateAndTimeHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateJanuary = new Date(2014, 0, 1), 11 | momentJanuary = moment('2014-01-01'), 12 | literalJanuary = '2014/01/01'; 13 | 14 | test('one arg (date)', function(assert) { 15 | assert.equal(dateAndTime(dateJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 16 | }); 17 | 18 | test('one arg (moment)', function(assert) { 19 | assert.equal(dateAndTime(momentJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 20 | }); 21 | 22 | test('one arg (literal)', function(assert) { 23 | assert.equal(dateAndTime(literalJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 24 | }); 25 | 26 | test('locale pt-br', function(assert) { 27 | assert.equal(dateAndTime(dateJanuary, 'pt-br', FAKE_HBS_CONTEXT), '1 de janeiro de 2014 às 00:00'); 28 | }); 29 | 30 | test('null date', function(assert) { 31 | assert.equal(dateAndTime(null, FAKE_HBS_CONTEXT), ''); 32 | }); 33 | 34 | test('blank date', function(assert) { 35 | assert.equal(dateAndTime(' ', FAKE_HBS_CONTEXT), ''); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/unit/helpers/day-of-the-week-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { dayOfTheWeek } from 'ember-cli-dates/helpers/day-of-the-week'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('DayOfTheWeekHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateJanuary = new Date(2014, 0, 1), 11 | momentJanuary = moment('2014-01-01'), 12 | literalJanuary = '2014/01/01'; 13 | 14 | test('one arg (date)', function(assert) { 15 | assert.equal(dayOfTheWeek(dateJanuary, FAKE_HBS_CONTEXT), 'Wednesday'); 16 | }); 17 | 18 | test('one arg (moment)', function(assert) { 19 | assert.equal(dayOfTheWeek(momentJanuary, FAKE_HBS_CONTEXT), 'Wednesday'); 20 | }); 21 | 22 | test('one arg (literal)', function(assert) { 23 | assert.equal(dayOfTheWeek(literalJanuary, FAKE_HBS_CONTEXT), 'Wednesday'); 24 | }); 25 | 26 | test('locale pt-br', function(assert) { 27 | assert.equal(dayOfTheWeek(dateJanuary, 'pt-br', FAKE_HBS_CONTEXT), 'quarta-feira'); 28 | }); 29 | 30 | test('null date', function(assert) { 31 | assert.equal(dayOfTheWeek(null, FAKE_HBS_CONTEXT), ''); 32 | }); 33 | 34 | test('blank date', function(assert) { 35 | assert.equal(dayOfTheWeek(' ', FAKE_HBS_CONTEXT), ''); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/unit/helpers/month-and-day-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { monthAndDay } from 'ember-cli-dates/helpers/month-and-day'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('MonthAndDayHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateJanuary = new Date(2014, 0, 1), 11 | momentJanuary = moment('2014-01-01'), 12 | literalJanuary = '2014/01/01'; 13 | 14 | test('one arg (date)', function(assert) { 15 | assert.equal(monthAndDay(dateJanuary, FAKE_HBS_CONTEXT), 'Jan 1st'); 16 | }); 17 | 18 | test('one arg (moment)', function(assert) { 19 | assert.equal(monthAndDay(momentJanuary, FAKE_HBS_CONTEXT), 'Jan 1st'); 20 | }); 21 | 22 | test('one arg (literal)', function(assert) { 23 | assert.equal(monthAndDay(literalJanuary, FAKE_HBS_CONTEXT), 'Jan 1st'); 24 | }); 25 | 26 | test('locale pt-br', function(assert) { 27 | assert.equal(monthAndDay(dateJanuary, 'pt-br', FAKE_HBS_CONTEXT), 'jan 1º'); 28 | }); 29 | 30 | test('null date', function(assert) { 31 | assert.equal(monthAndDay(null, FAKE_HBS_CONTEXT), ''); 32 | }); 33 | 34 | test('blank date', function(assert) { 35 | assert.equal(monthAndDay(' ', FAKE_HBS_CONTEXT), ''); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/unit/helpers/month-and-year-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { monthAndYear } from 'ember-cli-dates/helpers/month-and-year'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('MonthAndYearHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateJanuary = new Date(2014, 0, 1), 11 | momentJanuary = moment('2014-01-01'), 12 | literalJanuary = '2014/01/01'; 13 | 14 | test('one arg (date)', function(assert) { 15 | assert.equal(monthAndYear(dateJanuary, FAKE_HBS_CONTEXT), 'Jan 2014'); 16 | }); 17 | 18 | test('one arg (moment)', function(assert) { 19 | assert.equal(monthAndYear(momentJanuary, FAKE_HBS_CONTEXT), 'Jan 2014'); 20 | }); 21 | 22 | test('one arg (literal)', function(assert) { 23 | assert.equal(monthAndYear(literalJanuary, FAKE_HBS_CONTEXT), 'Jan 2014'); 24 | }); 25 | 26 | test('locale pt-br', function(assert) { 27 | assert.equal(monthAndYear(dateJanuary, 'pt-br', FAKE_HBS_CONTEXT), 'jan 2014'); 28 | }); 29 | 30 | test('null date', function(assert) { 31 | assert.equal(monthAndYear(null, FAKE_HBS_CONTEXT), ''); 32 | }); 33 | 34 | test('blank date', function(assert) { 35 | assert.equal(monthAndYear(' ', FAKE_HBS_CONTEXT), ''); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/unit/helpers/time-ago-in-words-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { timeAgoInWords } from 'ember-cli-dates/helpers/time-ago-in-words'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('TimeAgoInWordsHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateYesterday = new Date(new Date().valueOf() - 1000*3600*24), 11 | momentYesterday = moment().subtract(1, 'days'); 12 | 13 | test('one arg (date)', function(assert) { 14 | assert.equal(timeAgoInWords(dateYesterday, FAKE_HBS_CONTEXT), 'a day ago'); 15 | }); 16 | 17 | test('one arg (moment)', function(assert) { 18 | assert.equal(timeAgoInWords(momentYesterday, FAKE_HBS_CONTEXT), 'a day ago'); 19 | }); 20 | 21 | test('locale pt-br', function(assert) { 22 | assert.equal(timeAgoInWords(dateYesterday, 'pt-br', FAKE_HBS_CONTEXT), 'um dia atrás'); 23 | }); 24 | 25 | test('null date', function(assert) { 26 | assert.equal(timeAgoInWords(null, FAKE_HBS_CONTEXT), ''); 27 | }); 28 | 29 | test('blank date', function(assert) { 30 | assert.equal(timeAgoInWords(' ', FAKE_HBS_CONTEXT), ''); 31 | }); 32 | -------------------------------------------------------------------------------- /tests/unit/helpers/time-ahead-in-words-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { timeAheadInWords } from 'ember-cli-dates/helpers/time-ahead-in-words'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('TimeAheadInWordsHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateTomorrow = new Date(new Date().valueOf() + 1000*3600*24), 11 | momentTomorrow = moment().add(1, 'days'); 12 | 13 | test('one arg (date)', function(assert) { 14 | assert.equal(timeAheadInWords(dateTomorrow, FAKE_HBS_CONTEXT), 'in a day'); 15 | }); 16 | 17 | test('one arg (moment)', function(assert) { 18 | assert.equal(timeAheadInWords(momentTomorrow, FAKE_HBS_CONTEXT), 'in a day'); 19 | }); 20 | 21 | test('locale pt-br', function(assert) { 22 | assert.equal(timeAheadInWords(dateTomorrow, 'pt-br', FAKE_HBS_CONTEXT), 'em um dia'); 23 | }); 24 | 25 | test('null date', function(assert) { 26 | assert.equal(timeAheadInWords(null, FAKE_HBS_CONTEXT), ''); 27 | }); 28 | 29 | test('blank date', function(assert) { 30 | assert.equal(timeAheadInWords(' ', FAKE_HBS_CONTEXT), ''); 31 | }); 32 | -------------------------------------------------------------------------------- /tests/unit/helpers/time-delta-in-words-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { timeDeltaInWords } from 'ember-cli-dates/helpers/time-delta-in-words'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('TimeDeltaInWordsHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateYesterday = new Date(new Date().valueOf() - 1000*3600*24), 11 | momentYesterday = moment().subtract(1, 'days'); 12 | 13 | test('one arg (date)', function(assert) { 14 | assert.equal(timeDeltaInWords(dateYesterday, FAKE_HBS_CONTEXT), 'a day ago'); 15 | }); 16 | 17 | test('one arg (moment)', function(assert) { 18 | assert.equal(timeDeltaInWords(momentYesterday, FAKE_HBS_CONTEXT), 'a day ago'); 19 | }); 20 | 21 | test('locale pt-br', function(assert) { 22 | assert.equal(timeDeltaInWords(dateYesterday, 'pt-br', FAKE_HBS_CONTEXT), 'um dia atrás'); 23 | }); 24 | 25 | test('null date', function(assert) { 26 | assert.equal(timeDeltaInWords(null, FAKE_HBS_CONTEXT), ''); 27 | }); 28 | 29 | test('blank date', function(assert) { 30 | assert.equal(timeDeltaInWords(' ', FAKE_HBS_CONTEXT), ''); 31 | }); 32 | -------------------------------------------------------------------------------- /tests/unit/helpers/time-format-test.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment'; 2 | import { timeFormat } from 'ember-cli-dates/helpers/time-format'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('TimeFormatHelper'); 6 | 7 | moment.locale('en'); 8 | 9 | var FAKE_HBS_CONTEXT = {}, 10 | dateJanuary = new Date(2014, 0, 1), 11 | momentJanuary = moment('2014-01-01'), 12 | literalJanuary = '2014/01/01'; 13 | 14 | test('one arg (date)', function(assert) { 15 | assert.equal(timeFormat(dateJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014'); 16 | }); 17 | 18 | test('one arg (moment)', function(assert) { 19 | assert.equal(timeFormat(momentJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014'); 20 | }); 21 | 22 | test('one arg (literal)', function(assert) { 23 | assert.equal(timeFormat(literalJanuary, FAKE_HBS_CONTEXT), 'January 1, 2014'); 24 | }); 25 | 26 | test('two args (date, format)', function(assert) { 27 | assert.equal(timeFormat(dateJanuary, 'LLL', FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 28 | }); 29 | 30 | test('two args (moment, format)', function(assert) { 31 | assert.equal(timeFormat(momentJanuary, 'LLL', FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 32 | }); 33 | 34 | test('two args (literal, format)', function(assert) { 35 | assert.equal(timeFormat(literalJanuary, 'LLL', FAKE_HBS_CONTEXT), 'January 1, 2014 12:00 AM'); 36 | }); 37 | 38 | test('locale pt-br', function(assert) { 39 | assert.equal(timeFormat(dateJanuary, 'LL', 'pt-br', FAKE_HBS_CONTEXT), '1 de janeiro de 2014'); 40 | }); 41 | 42 | test('null date', function(assert) { 43 | assert.equal(timeFormat(null, FAKE_HBS_CONTEXT), ''); 44 | }); 45 | 46 | test('blank date', function(assert) { 47 | assert.equal(timeFormat(' ', FAKE_HBS_CONTEXT), ''); 48 | }); 49 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johno/ember-cli-dates/dc6affe08295846c3f93742e894fcd11c2b23060/vendor/.gitkeep --------------------------------------------------------------------------------