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

Fix 92 suppress output when date is null #93

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
dist: trusty
addons:
chrome: stable

language: node_js

node_js:
- 4
- 5
- 6
- 7
- 8

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "sh -e /etc/init.d/xvfb start"

before_install:
- npm install -g grunt-cli
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

install:
- npm prune && npm install
- node_modules/protractor/bin/webdriver-manager update --standalone --firefox
- node_modules/protractor/bin/webdriver-manager start 2>&1 &
- node_modules/protractor/bin/webdriver-manager update
- node_modules/protractor/bin/webdriver-manager start 2>&1 &
- sleep 3

script:
Expand Down
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module.exports = function(grunt) {

var dirs = {
src: 'src',
dist: 'dist',
demo: 'demo',
dist: 'dist'
};

// Project configuration.
Expand Down Expand Up @@ -56,9 +55,10 @@ module.exports = function(grunt) {
middleware: function(connect) {
var middlewares = [];
var serveStatic = require('serve-static');
middlewares.push(serveStatic(dirs.demo));
middlewares.push(serveStatic('demo'));
middlewares.push(connect().use('/node_modules', serveStatic('./node_modules')));
middlewares.push(connect().use('/dist', serveStatic(dirs.dist)));
middlewares.push(connect().use('/src', serveStatic(dirs.src)));
return middlewares;
}
},
Expand Down
17 changes: 16 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ <h3>You can use an ISO8601 String, a Date object or epoch time.</h3>
This repo was created <span time-ago from-time="2014-03-11T05:25:00Z"></span>
</div>

<div class="directive-example-not-found-property">
<h2>Directive Example - property not found</h2>
<p>You opened this demo page <time-ago from-time='{{ notFoundProperty }}'></time-ago></p>
</div>

<div class="filter-example-not-found-property">
<h2>Filter Example - property not found</h2>
<p>You opened this demo page {{ notFoundProperty | timeAgo }}</p>
</div>

<script src="node_modules/angular/angular.js"></script>
<script src="dist/angular-timeago.js"></script>
<script src="src/module.js"></script>
<script src="src/now-time.factory.js"></script>
<script src="src/time-ago-settings.constant.js"></script>
<script src="src/time-ago.directive.js"></script>
<script src="src/time-ago.factory.js"></script>
<script src="src/time-ago.filter.js"></script>
<script src="src/languages/time-ago-language-en_US.js"></script>
<script src="main.js"></script>
</body>
</html>
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@
},
"devDependencies": {
"angular-mocks": "^1.2.10",
"chai": "3.5.0",
"chai": "4.1.0",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
"grunt-contrib-clean": "1.1.0",
"grunt-contrib-concat": "1.0.1",
"grunt-contrib-connect": "1.0.2",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-jshint": "1.0.0",
"grunt-contrib-uglify": "2.0.0",
"grunt-contrib-jshint": "1.1.0",
"grunt-contrib-uglify": "3.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-jsbeautifier": "0.2.13",
"grunt-karma": "2.0.0",
"grunt-ng-annotate": "3.0.0",
"grunt-open": "0.2.3",
"grunt-protractor-runner": "4.0.0",
"grunt-protractor-runner": "5.0.0",
"grunt-release": "0.14.0",
"jquery": "3.1.1",
"karma": "1.3.0",
"karma-chrome-launcher": "2.0.0",
"jquery": "3.2.1",
"karma": "1.7.0",
"karma-chrome-launcher": "2.2.0",
"karma-mocha": "1.3",
"karma-ng-html2js-preprocessor": "1.0.0",
"karma-phantomjs-launcher": "1.0.2",
"karma-phantomjs-launcher": "1.0.4",
"matchdep": "1.0.1",
"mocha": "3.1.2",
"phantomjs-prebuilt": "2.1.13",
"protractor": "4.0.11",
"serve-static": "1.11.1"
"mocha": "3.4.2",
"phantomjs-prebuilt": "2.1.14",
"protractor": "5.1.2",
"serve-static": "1.12.3"
},
"main": "dist/angular-timeago.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion protractor-e2e.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ exports.config = {
specs: ['test/e2e/*.spec.js', 'test/e2e/**/*.spec.js'],
baseUrl: 'http://localhost:9999',
capabilities: {
browserName: 'firefox'
browserName: 'chrome'
}
};
16 changes: 13 additions & 3 deletions src/time-ago.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ angular.module('yaru22.angular-timeago').directive('timeAgo', function(timeAgo,

// Track changes to fromTime
scope.$watch('fromTime', function() {
fromTime = timeAgo.parse(scope.fromTime);
fromTime = null;
if (!!scope.fromTime) {
fromTime = timeAgo.parse(scope.fromTime);
}
});

// Track changes to time difference
scope.$watch(function() {
return nowTime() - fromTime;
if (!!fromTime) {
return nowTime() - fromTime;
}
return null;
}, function(value) {
angular.element(elem).text(timeAgo.inWords(value, fromTime, scope.format));
var text = '';
if (!!value) {
text = timeAgo.inWords(value, fromTime, scope.format);
}
angular.element(elem).text(text);
});
}
};
Expand Down
9 changes: 6 additions & 3 deletions src/time-ago.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

angular.module('yaru22.angular-timeago').filter('timeAgo', function(nowTime, timeAgo) {
function timeAgoFilter(value, format, timezone) {
var fromTime = timeAgo.parse(value);
var diff = nowTime() - fromTime;
return timeAgo.inWords(diff, fromTime, format, timezone);
if (!!value) {
var fromTime = timeAgo.parse(value);
var diff = nowTime() - fromTime;
return timeAgo.inWords(diff, fromTime, format, timezone);
}
return null;
}
timeAgoFilter.$stateful = true;
return timeAgoFilter;
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/timeAgo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ describe('basic frontend testing', function () {
expect(element(by.css('.filter-example')).getText()).toMatch(/^(Filter Example\nYou opened this demo page )(less than|about)( a minute ago)$/);
});

it('time ago directive - property not found', function () {
expect(element(by.css('.directive-example-not-found-property')).getText()).toMatch(/^(Directive Example - property not found\nYou opened this demo page)$/);
});

it('time ago filter - property not found', function () {
expect(element(by.css('.filter-example-not-found-property')).getText()).toMatch(/^(Filter Example - property not found\nYou opened this demo page)$/);
});

it('loading time', function () {
var testStartTime = Date.now();
element(by.css('.loading-time')).getText().then(function (loadingTimeText) {
Expand Down
6 changes: 5 additions & 1 deletion test/unit/timeAgoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('timeAgo', function () {
ngDateFilter = dateFilter;
timeAgo = _timeAgo_;
timeAgoSettings = _timeAgoSettings_;
timeAgoSettings.overrideLang = undefined;
}));

it('test filter', function () {
Expand All @@ -35,7 +36,7 @@ describe('timeAgo', function () {
expect(filter(nowDate)).to.equal([strs.prefixAgo, strs.seconds, strs.suffixAgo].join(' ').trim());
});

it('settings.fullDateAfterSeconds works', function() {
it('settings.fullDateAfterSeconds works', function () {
// force it to display the full date always
timeAgoSettings.fullDateAfterSeconds = 0;
var nowDate = new Date();
Expand All @@ -46,4 +47,7 @@ describe('timeAgo', function () {
expect(ngDateString).to.equal(taDateString);
});

it('accept empty property', function () {
expect(filter(undefined)).to.equal(null);
});
});