diff --git a/.travis.yml b/.travis.yml index 8336d58..481a518 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ node_js: notifications: email: true -before_script: +install: + - npm install - npm install -g grunt-cli - npm install bower - bower install - script: - grunt tests diff --git a/README.md b/README.md index 611887d..83f19f6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -## angular-timer — A simple, re-usable, inter-operable timer directive [![Build Status](https://travis-ci.org/siddii/angular-timer.png)](https://travis-ci.org/siddii/angular-timer) +## angular-timer — A simple, re-usable, inter-operable timer directive + +[![Build Status](https://travis-ci.org/siddii/angular-timer.png)](https://travis-ci.org/siddii/angular-timer) +[![](https://www.codeshelter.co/static/badges/badge-flat.svg)](https://www.codeshelter.co/) ### Getting started With any of the following options... diff --git a/app/js/_timer.js b/app/js/_timer.js index 3897f7a..70ca899 100644 --- a/app/js/_timer.js +++ b/app/js/_timer.js @@ -114,7 +114,7 @@ var timerModule = angular.module('timer', []) } }); - $scope.start = $element[0].start = function () { + $scope.start = function () { $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment(); $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null; if (!angular.isNumber($scope.countdown)) { @@ -123,9 +123,17 @@ var timerModule = angular.module('timer', []) resetTimeout(); tick(); $scope.isRunning = true; + $scope.$emit('timer-started', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.resume = $element[0].resume = function () { + $scope.resume = function () { resetTimeout(); if ($scope.countdownattr) { $scope.countdown += 1; @@ -133,15 +141,30 @@ var timerModule = angular.module('timer', []) $scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime)))); tick(); $scope.isRunning = true; + $scope.$emit('timer-started', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.stop = $scope.pause = $element[0].stop = $element[0].pause = function () { + $scope.stop = $scope.pause = function () { var timeoutId = $scope.timeoutId; $scope.clear(); - $scope.$emit('timer-stopped', {timeoutId: timeoutId, millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days}); + $scope.$emit('timer-stopped', { + timeoutId: timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.clear = $element[0].clear = function () { + $scope.clear = function () { // same as stop but without the event being triggered $scope.stoppedTime = moment(); resetTimeout(); @@ -149,7 +172,7 @@ var timerModule = angular.module('timer', []) $scope.isRunning = false; }; - $scope.reset = $element[0].reset = function () { + $scope.reset = function () { $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment(); $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null; $scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined; @@ -157,6 +180,14 @@ var timerModule = angular.module('timer', []) tick(); $scope.isRunning = false; $scope.clear(); + $scope.$emit('timer-reseted', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; $element.bind('$destroy', function () { @@ -249,18 +280,15 @@ var timerModule = angular.module('timer', []) if ($scope.countdownattr) { $scope.millis = $scope.countdownattr * 1000; - $scope.addCDSeconds = $element[0].addCDSeconds = function (extraSeconds) { + $scope.addCDSeconds = function (extraSeconds) { $scope.countdown += extraSeconds; - $scope.$digest(); if (!$scope.isRunning) { $scope.start(); } }; $scope.$on('timer-add-cd-seconds', function (e, extraSeconds) { - $timeout(function () { - $scope.addCDSeconds(extraSeconds); - }); + $scope.addCDSeconds(extraSeconds); }); $scope.$on('timer-set-countdown-seconds', function (e, countdownSeconds) { @@ -306,11 +334,20 @@ var timerModule = angular.module('timer', []) //We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5 $scope.timeoutId = setTimeout(function () { - tick(); - $scope.$digest(); + tick(); + // since you choose not to use $timeout, at least preserve angular cycle two way data binding + // by calling $scope.$apply() instead of $scope.$digest() + $scope.$apply(); }, $scope.interval - adjustment); - $scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis, timerElement: $element[0]}); + $scope.$emit('timer-tick', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); if ($scope.countdown > 0) { $scope.countdown--; @@ -337,7 +374,50 @@ var timerModule = angular.module('timer', []) } }] }; - }]); + }]) + .directive('timerControls', function() { + return { + restrict: 'EA', + scope: true, + controller: ['$scope', function($scope) { + $scope.timerStatus = "reset"; + $scope.$on('timer-started', function() { + $scope.timerStatus = "started"; + }); + $scope.$on('timer-stopped', function() { + $scope.timerStatus = "stopped"; + }); + $scope.$on('timer-reset', function() { + $scope.timerStatus = "reset"; + }); + $scope.timerStart = function() { + $scope.$broadcast('timer-start'); + }; + $scope.timerStop = function() { + $scope.$broadcast('timer-stop'); + }; + $scope.timerResume = function() { + $scope.$broadcast('timer-resume'); + }; + $scope.timerToggle = function() { + switch ($scope.timerStatus) { + case "started": + $scope.timerStop(); + break; + case "stopped": + $scope.timerResume(); + break; + case "reset": + $scope.timerStart(); + break; + } + }; + $scope.timerAddCDSeconds = function(extraSeconds) { + $scope.$broadcast('timer-add-cd-seconds', extraSeconds); + }; + }] + }; + }); /* commonjs package manager support (eg componentjs) */ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){ diff --git a/app/js/i18nService.js b/app/js/i18nService.js index b64a8c0..9f7a596 100644 --- a/app/js/i18nService.js +++ b/app/js/i18nService.js @@ -21,8 +21,9 @@ app.factory('I18nService', function() { this.language = this.fallback; } - //moment init - moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive + // It should be handle by the user's application itself, and not inside the directive + // moment init + // moment.locale(this.language); //human duration init, using it because momentjs does not allow accurate time ( // momentJS: a few moment ago, human duration : 4 seconds ago @@ -44,13 +45,13 @@ app.factory('I18nService', function() { if (typeof this.timeHumanizer != 'undefined'){ time = { - 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["milliseconds"] }), - 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["seconds"] }), - 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["minutes", "seconds"] }) , - 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["hours", "minutes", "seconds"] }) , - 'days' : this.timeHumanizer(diffFromAlarm, { units: ["days", "hours", "minutes", "seconds"] }) , - 'months' : this.timeHumanizer(diffFromAlarm, { units: ["months", "days", "hours", "minutes", "seconds"] }) , - 'years' : this.timeHumanizer(diffFromAlarm, { units: ["years", "months", "days", "hours", "minutes", "seconds"] }) + 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["ms"] }), + 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["s"] }), + 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["m", "s"] }) , + 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["h", "m", "s"] }) , + 'days' : this.timeHumanizer(diffFromAlarm, { units: ["d", "h", "m", "s"] }) , + 'months' : this.timeHumanizer(diffFromAlarm, { units: ["mo", "d", "h", "m", "s"] }) , + 'years' : this.timeHumanizer(diffFromAlarm, { units: ["y", "mo", "d", "h", "m", "s"] }) }; } else { diff --git a/bower.json b/bower.json index 6c3b8bf..829ba31 100644 --- a/bower.json +++ b/bower.json @@ -1,17 +1,17 @@ { - "author": "Adrian Wardell", + "author": "Siddique Hameed", "name": "angular-timer", - "version": "1.3.4", - "homepage": "https://github.com/june07/angular-timer", + "version": "1.3.5", + "homepage": "https://github.com/siddii/angular-timer", "description": "Angular-Timer : A simple AngularJS directive demonstrating re-usability & interoperability", "repository": { "type": "git", - "url": "git://github.com/june07/angular-timer.git" + "url": "git://github.com/siddii/angular-timer.git" }, "dependencies": { "angular": ">= 1.0.7", - "moment": "~2.9.0", - "humanize-duration": "~2.8.0" + "moment": "~2.11.2", + "humanize-duration": "~3.10.0" }, "devDependencies": { "bootstrap": "2.3.2", diff --git a/bower_components/humanize-duration/.bower.json b/bower_components/humanize-duration/.bower.json index b2493c7..b7eae06 100644 --- a/bower_components/humanize-duration/.bower.json +++ b/bower_components/humanize-duration/.bower.json @@ -2,6 +2,7 @@ "name": "humanize-duration", "authors": [ "Evan Hahn (http://evanhahn.com)", + "Óli Tómas Freysson (https://github.com/olitomas)", "Martin Prins (https://github.com/magarcia)", "Filipi Siqueira (https://github.com/filipi777)", "Peter Rekdal Sunde (https://github.com/peters)", @@ -9,9 +10,18 @@ "Eileen Li (https://github.com/eileen3)", "Tommy Brunn (https://github.com/Nevon)", "Giovanni Pellerano (https://github.com/evilaliv3)", - "Rahma Sghaier (https://twitter.com/sghaierrahma)" + "Rahma Sghaier (https://twitter.com/sghaierrahma)", + "Evgenios Kastanias (https://github.com/evgenios)", + "Oleksii Mylotskyi (https://github.com/spalax)", + "Matthew Brandly (https://github.com/brandly)", + "Patrik Simek (https://github.com/patriksimek)", + "Toni Helminen (https://github.com/tonihelminen)", + "Vidmantas Drasutis (https://github.com/drasius2)", + "Manh Tuan (https://github.com/J2TeaM)", + "Leonard Lee (https://github.com/sheeeng)", + "Jesse Jackson (https://github.com/jsejcksn)" ], - "version": "2.8.0", + "version": "3.10.0", "description": "Convert millisecond durations to English and many other languages.", "main": "humanize-duration.js", "homepage": "https://github.com/EvanHahn/HumanizeDuration.js", @@ -26,7 +36,7 @@ "years", "months" ], - "license": "WTFPL", + "license": "Unlicense", "ignore": [ "**/.*", "node_modules", @@ -38,13 +48,13 @@ "type": "git", "url": "git://github.com/EvanHahn/HumanizeDuration.js.git" }, - "_release": "2.8.0", + "_release": "3.10.0", "_resolution": { "type": "version", - "tag": "v2.8.0", - "commit": "dcab6eaf100968c008351c70ae3dea9a8a86d929" + "tag": "v3.10.0", + "commit": "18243414dc4ce75d93f6a501f0e88130f2126421" }, - "_source": "git://github.com/EvanHahn/HumanizeDuration.js.git", - "_target": "~2.8.0", + "_source": "https://github.com/EvanHahn/HumanizeDuration.js.git", + "_target": "~3.10.0", "_originalSource": "humanize-duration" } \ No newline at end of file diff --git a/bower_components/humanize-duration/CONTRIBUTING.md b/bower_components/humanize-duration/CONTRIBUTING.md index d45bdd3..4ab6c27 100644 --- a/bower_components/humanize-duration/CONTRIBUTING.md +++ b/bower_components/humanize-duration/CONTRIBUTING.md @@ -3,13 +3,13 @@ How to contribute This assumes you have Node and npm installed. -1. Fork the repo. +1. Fork the repo on GitHub. 1. Clone the repo. 1. Run `npm install`. -1. Make your changes. Please add tests! If adding a new language, define some tests in *test/definitions*. +1. Make your changes. _Please add tests!_ If adding a new language, define some tests in *test/definitions*. 1. Update `HISTORY.md` with your changes. 1. If adding a new language, add it to the README. -1. Credit yourself in the README and in `package.json`. +1. Credit yourself in the README, in `package.json`, and in `bower.json`. 1. Make sure `npm test` doesn't have any errors. 1. Make sure `npm run hint` doesn't give any JSHint errors. 1. Submit your pull request! diff --git a/bower_components/humanize-duration/LICENSE.txt b/bower_components/humanize-duration/LICENSE.txt index 5c93f45..00d2e13 100644 --- a/bower_components/humanize-duration/LICENSE.txt +++ b/bower_components/humanize-duration/LICENSE.txt @@ -1,13 +1,24 @@ - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - Version 2, December 2004 +This is free and unencumbered software released into the public domain. - Copyright (C) 2004 Sam Hocevar +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. - Everyone is permitted to copy and distribute verbatim or modified - copies of this license document, and changing it is allowed as long - as the name is changed. +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. - 0. You just DO WHAT THE FUCK YOU WANT TO. +For more information, please refer to \ No newline at end of file diff --git a/bower_components/humanize-duration/README.md b/bower_components/humanize-duration/README.md index 0343228..dbeec79 100644 --- a/bower_components/humanize-duration/README.md +++ b/bower_components/humanize-duration/README.md @@ -1,15 +1,15 @@ Humanize Duration ================= - [![npm version](https://badge.fury.io/js/humanize-duration.svg)](https://npmjs.org/package/humanize-duration) [![build status](https://travis-ci.org/EvanHahn/HumanizeDuration.js.svg?branch=master)](https://travis-ci.org/EvanHahn/HumanizeDuration.js) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) I have the time in milliseconds and I want it to become "30 minutes" or "3 days, 1 hour". Enter Humanize Duration! Basic usage ----------- -This package is available as *humanize-duration* in npm and Bower. You can also include the JavaScript in the browser. +This package is available as *humanize-duration* on [npm](https://www.npmjs.com/package/humanize-duration) and Bower. You can also include the JavaScript file in the browser. In the browser: @@ -23,7 +23,7 @@ humanizeDuration(12000) In Node (or Browserify or Webpack or anywhere with CommonJS): ```js -var humanizeDuration = require("humanize-duration") +var humanizeDuration = require('humanize-duration') humanizeDuration(12000) ``` @@ -33,39 +33,117 @@ Usage By default, Humanize Duration will humanize down to the second, and will return a decimal for the smallest unit. It will humanize in English by default. ```js -humanizeDuration(3000) // "3 seconds" -humanizeDuration(2015) // "2.25 seconds" -humanizeDuration(97320000) // "1 day, 3 hours, 2 minutes" +humanizeDuration(3000) // '3 seconds' +humanizeDuration(2015) // '2.25 seconds' +humanizeDuration(97320000) // '1 day, 3 hours, 2 minutes' ``` +### Options + You can change the settings by passing options as the second argument: +**language** + +Language for unit display (accepts an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) from one of the [supported languages](#supported-languages)). + +```js +humanizeDuration(3000, { language: 'es' }) // '3 segundos' +humanizeDuration(5000, { language: 'ko' }) // '5 초' +``` + +**delimiter** + +String to display between the previous unit and the next value. + +```js +humanizeDuration(22140000, { delimiter: ' and ' }) // '6 hours and 9 minutes' +humanizeDuration(22140000, { delimiter: '--' }) // '6 hours--9 minutes' +``` + +**spacer** + +String to display between each value and unit. + +```js +humanizeDuration(260040000, { spacer: ' whole ' }) // '3 whole days, 14 whole minutes' +humanizeDuration(260040000, { spacer: '' }) // '3days, 14minutes' +``` + +**largest** + +Number representing the maximum number of units to display for the duration. + +```js +humanizeDuration(1000000000000) // '31 years, 8 months, 1 week, 19 hours, 46 minutes, 40 seconds' +humanizeDuration(1000000000000, { largest: 2 }) // '31 years, 8 month' +``` + +**units** + +Array of strings to define which units are used to display the duration (if needed). Can be one, or a combination of any, of the following: `['y', 'mo', 'w', 'd', 'h', 'm', 's', 'ms']` + +```js +humanizeDuration(3600000, { units: ['h'] }) // '1 hour' +humanizeDuration(3600000, { units: ['m'] }) // '60 minutes' +humanizeDuration(3600000, { units: ['d', 'h'] }) // '1 hour' +``` + +**round** + +Boolean value. Use `true` to [round](https://en.wikipedia.org/wiki/Rounding#Round_half_up) the smallest unit displayed (can be combined with `largest` and `units`). + ```js -humanizeDuration(3000, { language: "es" }) // "3 segundos" -humanizeDuration(5000, { language: "ko" }) // "5 초" +humanizeDuration(1200) // '1.2 seconds' +humanizeDuration(1200, { round: true }) // '1 second' +humanizeDuration(1600, { round: true }) // '2 seconds' +``` + +**decimal** -humanizeDuration(22140000, { delimiter: " and " }) // "6 hours and 9 minutes" -humanizeDuration(22140000, { delimiter: "--" }) // "6 hours--9 minutes" +String to substitute for the decimal point in a decimal fraction. -humanizeDuration(260040000, { spacer: " whole " }) // "3 whole days, 14 whole minutes" -humanizeDuration(260040000, { spacer: "" }) // "3days, 14minutes" +```js +humanizeDuration(1200) // '1.2 seconds' +humanizeDuration(1200, { decimal: ' point ' }) // '1 point 2 seconds' +``` -humanizeDuration(3600000, { units: ["hours"] }) // "1 hour" -humanizeDuration(3600000, { units: ["days", "hours"] }) // "1 hour" -humanizeDuration(3600000, { units: ["minutes"] }) // "60 minutes" +**conjunction** -humanizeDuration(1200) // "1.2 seconds" -humanizeDuration(1200, { round: true }) // "1 second" -humanizeDuration(1600, { round: true }) // "2 seconds" +String to include before the final unit. You can also set `serialComma` to `false` to eliminate the final comma. -humanizeDuration(150000) // "2.5 minutes" -humanizeDuration(150000, { halfUnit: false }) // "2 minutes, 30 seconds" +```js +humanizeDuration(22140000, { conjunction: ' and ' }) // '6 hours and 9 minutes' +humanizeDuration(22141000, { conjunction: ' and ' }) // '6 hours, 9 minutes, and 1 second' +humanizeDuration(22140000, { conjunction: ' and ', serialComma: false }) // '6 hours and 9 minutes' +humanizeDuration(22141000, { conjunction: ' and ', serialComma: false }) // '6 hours, 9 minutes and 1 second' +``` -humanizeDuration(3600000, { - language: "es", - units: ["minutes"] +**unitMeasures** + +Customize the value used to calculate each unit of time. + +```js +humanizeDuration(400) // '0.4 seconds' +humanizeDuration(400, { // '1 year, 1 month, 5 days' + unitMeasures: { + y: 365, + mo: 30, + w: 7, + d: 1 + } }) -// "60 minutos" +``` + +**Combined example** + +```js +humanizeDuration(3602000, { + language: 'es', + round: true, + spacer: ' glorioso ', + units: ['m'] +}) +// '60 glorioso minutos' ``` ### Humanizers @@ -74,34 +152,34 @@ If you find yourself setting same options over and over again, you can create a ```js var spanishHumanizer = humanizeDuration.humanizer({ - language: "es", - units: ["years", "months", "days"] + language: 'es', + units: ['y', 'mo', 'd'] }) -spanishHumanizer(71177400000) // "2 años, 3 meses, 2 días" -spanishHumanizer(71177400000, { units: ["days", "hours"] }) // "823 días, 19.5 horas" +spanishHumanizer(71177400000) // '2 años, 3 meses, 2 días' +spanishHumanizer(71177400000, { units: ['d', 'h'] }) // '823 días, 19.5 horas' ``` You can also add new languages to humanizers. For example: ```js var shortEnglishHumanizer = humanizeDuration.humanizer({ - language: "shortEn", + language: 'shortEn', languages: { shortEn: { - year: function() { return "y"; }, - month: function() { return "mo"; }, - week: function() { return "w"; }, - day: function() { return "d"; }, - hour: function() { return "h"; }, - minute: function() { return "m"; }, - second: function() { return "s"; }, - millisecond: function() { return "ms"; }, + y: function() { return 'y' }, + mo: function() { return 'mo' }, + w: function() { return 'w' }, + d: function() { return 'd' }, + h: function() { return 'h' }, + m: function() { return 'm' }, + s: function() { return 's' }, + ms: function() { return 'ms' }, } } }) -shortEnglishHumanizer(15600000) // "4 h, 20 m" +shortEnglishHumanizer(15600000) // '4 h, 20 m' ``` You can also add languages after initializing: @@ -110,7 +188,7 @@ You can also add languages after initializing: var humanizer = humanizeDuration.humanizer() humanizer.languages.shortEn = { - year: function(c) { return c + "y"; }, + y: function(c) { return c + 'y' }, // ... ``` @@ -121,34 +199,47 @@ Supported languages Humanize Duration supports the following languages: -* Arabic (ar) -* Catalan (ca) -* Chinese, simplified (zh-CN) -* Chinese, traditional (zh-TW) -* Danish (da) -* Dutch (nl) -* English (en) -* French (fr) -* German (de) -* Hungarian (hu) -* Italian (it) -* Japanese (ja) -* Korean (ko) -* Norwegian (nob) -* Polish (pl) -* Portuguese (pt) -* Russian (ru) -* Spanish (es) -* Swedish (sv) -* Turkish (tr) +| Language | Code | +|----------------------|---------| +| Arabic | `ar` | +| Catalan | `ca` | +| Chinese, simplified | `zh_CN` | +| Chinese, traditional | `zh_TW` | +| Czech | `cs` | +| Danish | `da` | +| Dutch | `nl` | +| English | `en` | +| Finnish | `fi` | +| French | `fr` | +| German | `de` | +| Greek | `gr` | +| Hungarian | `hu` | +| Icelandic | `is` | +| Indonesian | `id` | +| Italian | `it` | +| Japanese | `ja` | +| Korean | `ko` | +| Lithuanian | `lt` | +| Malay | `ms` | +| Norwegian | `no` | +| Polish | `pl` | +| Portuguese | `pt` | +| Russian | `ru` | +| Spanish | `es` | +| Swedish | `sv` | +| Turkish | `tr` | +| Ukrainian | `uk` | +| Vietnamese | `vi` | For a list of supported languages, you can use the `getSupportedLanguages` function. ```js humanizeDuration.getSupportedLanguages() -// ["ar", "ca", "da", "de" ...] +// ['ar', 'ca', 'da', 'de' ...] ``` +This function won't return any new languages you define; it will only return the defaults supported by the library. + Credits ------- @@ -162,5 +253,21 @@ Lovingly made by [Evan Hahn](http://evanhahn.com/) with help from: * [Tommy Brunn](https://github.com/Nevon) for Swedish support * [Giovanni Pellerano](https://github.com/evilaliv3) for Italian support * [Rahma Sghaier](https://twitter.com/sghaierrahma) for Arabic support - -Licensed under the WTFPL, so you can do whatever you want. Enjoy! +* [Evgenios Kastanias](https://github.com/evgenios) for Greek support +* [Oleksii Mylotskyi](https://github.com/spalax) for Ukrainian support +* [Patrik Simek](https://github.com/patriksimek) for Czech support +* [Toni Helminen](https://github.com/tonihelminen) for Finnish support +* [Vidmantas Drasutis](https://github.com/Drasius2) for Lithuanian support +* [Manh Tuan](https://github.com/J2TeaM) for Vietnamese support +* [Leonard Lee](https://github.com/sheeeng) for Indonesian & Malay support +* [Jesse Jackson](https://github.com/jsejcksn) for documentation help +* [Óli Tómas Freysson](https://github.com/olitomas) for Icelandic support + +Licensed under the permissive [Unlicense](http://unlicense.org/). Enjoy! + +Related modules +--------------- + +* [angularjs-humanize-duration](https://github.com/sebastianhaas/angularjs-humanize-duration) +* [millisec](https://github.com/sungwoncho/millisec) +* [HumanizeDuration.ts](https://github.com/Nightapes/HumanizeDuration.ts), a TypeScript version of this module diff --git a/bower_components/humanize-duration/bower.json b/bower_components/humanize-duration/bower.json index b68a4bf..75d5dfd 100644 --- a/bower_components/humanize-duration/bower.json +++ b/bower_components/humanize-duration/bower.json @@ -2,6 +2,7 @@ "name": "humanize-duration", "authors": [ "Evan Hahn (http://evanhahn.com)", + "Óli Tómas Freysson (https://github.com/olitomas)", "Martin Prins (https://github.com/magarcia)", "Filipi Siqueira (https://github.com/filipi777)", "Peter Rekdal Sunde (https://github.com/peters)", @@ -9,9 +10,18 @@ "Eileen Li (https://github.com/eileen3)", "Tommy Brunn (https://github.com/Nevon)", "Giovanni Pellerano (https://github.com/evilaliv3)", - "Rahma Sghaier (https://twitter.com/sghaierrahma)" + "Rahma Sghaier (https://twitter.com/sghaierrahma)", + "Evgenios Kastanias (https://github.com/evgenios)", + "Oleksii Mylotskyi (https://github.com/spalax)", + "Matthew Brandly (https://github.com/brandly)", + "Patrik Simek (https://github.com/patriksimek)", + "Toni Helminen (https://github.com/tonihelminen)", + "Vidmantas Drasutis (https://github.com/drasius2)", + "Manh Tuan (https://github.com/J2TeaM)", + "Leonard Lee (https://github.com/sheeeng)", + "Jesse Jackson (https://github.com/jsejcksn)" ], - "version": "2.8.0", + "version": "3.10.0", "description": "Convert millisecond durations to English and many other languages.", "main": "humanize-duration.js", "homepage": "https://github.com/EvanHahn/HumanizeDuration.js", @@ -26,7 +36,7 @@ "years", "months" ], - "license": "WTFPL", + "license": "Unlicense", "ignore": [ "**/.*", "node_modules", diff --git a/bower_components/humanize-duration/humanize-duration.js b/bower_components/humanize-duration/humanize-duration.js index 4bb2307..4270360 100644 --- a/bower_components/humanize-duration/humanize-duration.js +++ b/bower_components/humanize-duration/humanize-duration.js @@ -1,381 +1,553 @@ // HumanizeDuration.js - http://git.io/j0HgmQ -(function() { - - var UNITS = { - year: 31557600000, - month: 2629800000, - week: 604800000, - day: 86400000, - hour: 3600000, - minute: 60000, - second: 1000, - millisecond: 1 - }; - +;(function () { var languages = { ar: { - year: function(c) { return ((c === 1) ? "سنة" : "سنوات"); }, - month: function(c) { return ((c === 1) ? "شهر" : "أشهر"); }, - week: function(c) { return ((c === 1) ? "أسبوع" : "أسابيع"); }, - day: function(c) { return ((c === 1) ? "يوم" : "أيام"); }, - hour: function(c) { return ((c === 1) ? "ساعة" : "ساعات"); }, - minute: function(c) { return ((c === 1) ? "دقيقة" : "دقائق"); }, - second: function(c) { return ((c === 1) ? "ثانية" : "ثواني"); }, - millisecond: function(c) { return ((c === 1) ? "جزء من الثانية" : "أجزاء من الثانية"); } + y: function (c) { return c === 1 ? 'سنة' : 'سنوات' }, + mo: function (c) { return c === 1 ? 'شهر' : 'أشهر' }, + w: function (c) { return c === 1 ? 'أسبوع' : 'أسابيع' }, + d: function (c) { return c === 1 ? 'يوم' : 'أيام' }, + h: function (c) { return c === 1 ? 'ساعة' : 'ساعات' }, + m: function (c) { return c === 1 ? 'دقيقة' : 'دقائق' }, + s: function (c) { return c === 1 ? 'ثانية' : 'ثواني' }, + ms: function (c) { return c === 1 ? 'جزء من الثانية' : 'أجزاء من الثانية' }, + decimal: ',' }, ca: { - year: function(c) { return "any" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "mes" + ((c !== 1) ? "os" : ""); }, - week: function(c) { return "setman" + ((c !== 1) ? "es" : "a"); }, - day: function(c) { return "di" + ((c !== 1) ? "es" : "a"); }, - hour: function(c) { return "hor" + ((c !== 1) ? "es" : "a"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segon" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milisegon" + ((c !== 1) ? "s" : "" ); } + y: function (c) { return 'any' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'os' : '') }, + w: function (c) { return 'setman' + (c !== 1 ? 'es' : 'a') }, + d: function (c) { return 'di' + (c !== 1 ? 'es' : 'a') }, + h: function (c) { return 'hor' + (c !== 1 ? 'es' : 'a') }, + m: function (c) { return 'minut' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segon' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milisegon' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + cs: { + y: function (c) { return ['rok', 'roku', 'roky', 'let'][getCzechForm(c)] }, + mo: function (c) { return ['měsíc', 'měsíce', 'měsíce', 'měsíců'][getCzechForm(c)] }, + w: function (c) { return ['týden', 'týdne', 'týdny', 'týdnů'][getCzechForm(c)] }, + d: function (c) { return ['den', 'dne', 'dny', 'dní'][getCzechForm(c)] }, + h: function (c) { return ['hodina', 'hodiny', 'hodiny', 'hodin'][getCzechForm(c)] }, + m: function (c) { return ['minuta', 'minuty', 'minuty', 'minut'][getCzechForm(c)] }, + s: function (c) { return ['sekunda', 'sekundy', 'sekundy', 'sekund'][getCzechForm(c)] }, + ms: function (c) { return ['milisekunda', 'milisekundy', 'milisekundy', 'milisekund'][getCzechForm(c)] }, + decimal: ',' }, da: { - year: "år", - month: function(c) { return "måned" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "uge" + ((c !== 1) ? "r" : ""); }, - day: function(c) { return "dag" + ((c !== 1) ? "e" : ""); }, - hour: function(c) { return "time" + ((c !== 1) ? "r" : ""); }, - minute: function(c) { return "minut" + ((c !== 1) ? "ter" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + y: 'år', + mo: function (c) { return 'måned' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'uge' + (c !== 1 ? 'r' : '') }, + d: function (c) { return 'dag' + (c !== 1 ? 'e' : '') }, + h: function (c) { return 'time' + (c !== 1 ? 'r' : '') }, + m: function (c) { return 'minut' + (c !== 1 ? 'ter' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, de: { - year: function(c) { return "Jahr" + ((c !== 1) ? "e" : ""); }, - month: function(c) { return "Monat" + ((c !== 1) ? "e" : ""); }, - week: function(c) { return "Woche" + ((c !== 1) ? "n" : ""); }, - day: function(c) { return "Tag" + ((c !== 1) ? "e" : ""); }, - hour: function(c) { return "Stunde" + ((c !== 1) ? "n" : ""); }, - minute: function(c) { return "Minute" + ((c !== 1) ? "n" : ""); }, - second: function(c) { return "Sekunde" + ((c !== 1) ? "n" : ""); }, - millisecond: function(c) { return "Millisekunde" + ((c !== 1) ? "n" : ""); } + y: function (c) { return 'Jahr' + (c !== 1 ? 'e' : '') }, + mo: function (c) { return 'Monat' + (c !== 1 ? 'e' : '') }, + w: function (c) { return 'Woche' + (c !== 1 ? 'n' : '') }, + d: function (c) { return 'Tag' + (c !== 1 ? 'e' : '') }, + h: function (c) { return 'Stunde' + (c !== 1 ? 'n' : '') }, + m: function (c) { return 'Minute' + (c !== 1 ? 'n' : '') }, + s: function (c) { return 'Sekunde' + (c !== 1 ? 'n' : '') }, + ms: function (c) { return 'Millisekunde' + (c !== 1 ? 'n' : '') }, + decimal: ',' }, en: { - year: function(c) { return "year" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "month" + ((c !== 1) ? "s" : ""); }, - week: function(c) { return "week" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "day" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hour" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minute" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "second" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "millisecond" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'year' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'month' + (c !== 1 ? 's' : '') }, + w: function (c) { return 'week' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'day' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hour' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minute' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'second' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'millisecond' + (c !== 1 ? 's' : '') }, + decimal: '.' }, es: { - year: function(c) { return "año" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "mes" + ((c !== 1) ? "es" : ""); }, - week: function(c) { return "semana" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "día" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hora" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minuto" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segundo" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milisegundo" + ((c !== 1) ? "s" : "" ); } + y: function (c) { return 'año' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'es' : '') }, + w: function (c) { return 'semana' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'día' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hora' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minuto' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segundo' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milisegundo' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + fi: { + y: function (c) { return c === 1 ? 'vuosi' : 'vuotta' }, + mo: function (c) { return c === 1 ? 'kuukausi' : 'kuukautta' }, + w: function (c) { return 'viikko' + (c !== 1 ? 'a' : '') }, + d: function (c) { return 'päivä' + (c !== 1 ? 'ä' : '') }, + h: function (c) { return 'tunti' + (c !== 1 ? 'a' : '') }, + m: function (c) { return 'minuutti' + (c !== 1 ? 'a' : '') }, + s: function (c) { return 'sekunti' + (c !== 1 ? 'a' : '') }, + ms: function (c) { return 'millisekunti' + (c !== 1 ? 'a' : '') }, + decimal: ',' }, fr: { - year: function(c) { return "an" + ((c !== 1) ? "s" : ""); }, - month: "mois", - week: function(c) { return "semaine" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "jour" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "heure" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minute" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "seconde" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milliseconde" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'an' + (c !== 1 ? 's' : '') }, + mo: 'mois', + w: function (c) { return 'semaine' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'jour' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'heure' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minute' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'seconde' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milliseconde' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + gr: { + y: function (c) { return c === 1 ? 'χρόνος' : 'χρόνια' }, + mo: function (c) { return c === 1 ? 'μήνας' : 'μήνες' }, + w: function (c) { return c === 1 ? 'εβδομάδα' : 'εβδομάδες' }, + d: function (c) { return c === 1 ? 'μέρα' : 'μέρες' }, + h: function (c) { return c === 1 ? 'ώρα' : 'ώρες' }, + m: function (c) { return c === 1 ? 'λεπτό' : 'λεπτά' }, + s: function (c) { return c === 1 ? 'δευτερόλεπτο' : 'δευτερόλεπτα' }, + ms: function (c) { return c === 1 ? 'χιλιοστό του δευτερολέπτου' : 'χιλιοστά του δευτερολέπτου' }, + decimal: ',' }, hu: { - year: "év", - month: "hónap", - week: "hét", - day: "nap", - hour: "óra", - minute: "perc", - second: "másodperc", - millisecond: "ezredmásodperc" + y: 'év', + mo: 'hónap', + w: 'hét', + d: 'nap', + h: 'óra', + m: 'perc', + s: 'másodperc', + ms: 'ezredmásodperc', + decimal: ',' + }, + id: { + y: 'tahun', + mo: 'bulan', + w: 'minggu', + d: 'hari', + h: 'jam', + m: 'menit', + s: 'detik', + ms: 'milidetik', + decimal: '.' + }, + is: { + y: 'ár', + mo: function (c) { return 'mánuð' + (c !== 1 ? 'ir' : 'ur') }, + w: function (c) { return 'vik' + (c !== 1 ? 'ur' : 'a') }, + d: function (c) { return 'dag' + (c !== 1 ? 'ar' : 'ur') }, + h: function (c) { return 'klukkutím' + (c !== 1 ? 'ar' : 'i') }, + m: function (c) { return 'mínút' + (c !== 1 ? 'ur' : 'a') }, + s: function (c) { return 'sekúnd' + (c !== 1 ? 'ur' : 'a') }, + ms: function (c) { return 'millisekúnd' + (c !== 1 ? 'ur' : 'a') }, + decimal: '.' }, it: { - year: function(c) { return "ann" + ((c !== 1) ? "i" : "o"); }, - month: function(c) { return "mes" + ((c !== 1) ? "i" : "e"); }, - week: function(c) { return "settiman" + ((c !== 1) ? "e" : "a"); }, - day: function(c) { return "giorn" + ((c !== 1) ? "i" : "o"); }, - hour: function(c) { return "or" + ((c !== 1) ? "e" : "a"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "i" : "o"); }, - second: function(c) { return "second" + ((c !== 1) ? "i" : "o"); }, - millisecond: function(c) { return "millisecond" + ((c !== 1) ? "i" : "o" ); } + y: function (c) { return 'ann' + (c !== 1 ? 'i' : 'o') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'i' : 'e') }, + w: function (c) { return 'settiman' + (c !== 1 ? 'e' : 'a') }, + d: function (c) { return 'giorn' + (c !== 1 ? 'i' : 'o') }, + h: function (c) { return 'or' + (c !== 1 ? 'e' : 'a') }, + m: function (c) { return 'minut' + (c !== 1 ? 'i' : 'o') }, + s: function (c) { return 'second' + (c !== 1 ? 'i' : 'o') }, + ms: function (c) { return 'millisecond' + (c !== 1 ? 'i' : 'o') }, + decimal: ',' }, ja: { - year: "年", - month: "月", - week: "週", - day: "日", - hour: "時間", - minute: "分", - second: "秒", - millisecond: "ミリ秒" + y: '年', + mo: '月', + w: '週', + d: '日', + h: '時間', + m: '分', + s: '秒', + ms: 'ミリ秒', + decimal: '.' }, ko: { - year: "년", - month: "개월", - week: "주일", - day: "일", - hour: "시간", - minute: "분", - second: "초", - millisecond: "밀리 초" + y: '년', + mo: '개월', + w: '주일', + d: '일', + h: '시간', + m: '분', + s: '초', + ms: '밀리 초', + decimal: '.' + }, + lt: { + y: function (c) { return ((c % 10 === 0) || (c % 100 >= 10 && c % 100 <= 20)) ? 'metų' : 'metai' }, + mo: function (c) { return ['mėnuo', 'mėnesiai', 'mėnesių'][getLithuanianForm(c)] }, + w: function (c) { return ['savaitė', 'savaitės', 'savaičių'][getLithuanianForm(c)] }, + d: function (c) { return ['diena', 'dienos', 'dienų'][getLithuanianForm(c)] }, + h: function (c) { return ['valanda', 'valandos', 'valandų'][getLithuanianForm(c)] }, + m: function (c) { return ['minutė', 'minutės', 'minučių'][getLithuanianForm(c)] }, + s: function (c) { return ['sekundė', 'sekundės', 'sekundžių'][getLithuanianForm(c)] }, + ms: function (c) { return ['milisekundė', 'milisekundės', 'milisekundžių'][getLithuanianForm(c)] }, + decimal: ',' + }, + ms: { + y: 'tahun', + mo: 'bulan', + w: 'minggu', + d: 'hari', + h: 'jam', + m: 'minit', + s: 'saat', + ms: 'milisaat', + decimal: '.' }, nl: { - year: "jaar", - month: function(c) { return (c === 1) ? "maand" : "maanden"; }, - week: function(c) { return (c === 1) ? "week" : "weken"; }, - day: function(c) { return (c === 1) ? "dag" : "dagen"; }, - hour: "uur", - minute: function(c) { return (c === 1) ? "minuut" : "minuten"; }, - second: function(c) { return (c === 1) ? "seconde" : "seconden"; }, - millisecond: function(c) { return (c === 1) ? "milliseconde" : "milliseconden"; } + y: 'jaar', + mo: function (c) { return c === 1 ? 'maand' : 'maanden' }, + w: function (c) { return c === 1 ? 'week' : 'weken' }, + d: function (c) { return c === 1 ? 'dag' : 'dagen' }, + h: 'uur', + m: function (c) { return c === 1 ? 'minuut' : 'minuten' }, + s: function (c) { return c === 1 ? 'seconde' : 'seconden' }, + ms: function (c) { return c === 1 ? 'milliseconde' : 'milliseconden' }, + decimal: ',' }, - nob: { - year: "år", - month: function(c) { return "måned" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "uke" + ((c !== 1) ? "r" : ""); }, - day: function(c) { return "dag" + ((c !== 1) ? "er" : ""); }, - hour: function(c) { return "time" + ((c !== 1) ? "r" : ""); }, - minute: function(c) { return "minutt" + ((c !== 1) ? "er" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + no: { + y: 'år', + mo: function (c) { return 'måned' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'uke' + (c !== 1 ? 'r' : '') }, + d: function (c) { return 'dag' + (c !== 1 ? 'er' : '') }, + h: function (c) { return 'time' + (c !== 1 ? 'r' : '') }, + m: function (c) { return 'minutt' + (c !== 1 ? 'er' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, pl: { - year: function(c) { return ["rok", "roku", "lata", "lat"][getPolishForm(c)]; }, - month: function(c) { return ["miesiąc", "miesiąca", "miesiące", "miesięcy"][getPolishForm(c)]; }, - week: function(c) { return ["tydzień", "tygodnia", "tygodnie", "tygodni"][getPolishForm(c)]; }, - day: function(c) { return ["dzień", "dnia", "dni", "dni"][getPolishForm(c)]; }, - hour: function(c) { return ["godzina", "godziny", "godziny", "godzin"][getPolishForm(c)]; }, - minute: function(c) { return ["minuta", "minuty", "minuty", "minut"][getPolishForm(c)]; }, - second: function(c) { return ["sekunda", "sekundy", "sekundy", "sekund"][getPolishForm(c)]; }, - millisecond: function(c) { return ["milisekunda", "milisekundy", "milisekundy", "milisekund"][getPolishForm(c)]; } + y: function (c) { return ['rok', 'roku', 'lata', 'lat'][getPolishForm(c)] }, + mo: function (c) { return ['miesiąc', 'miesiąca', 'miesiące', 'miesięcy'][getPolishForm(c)] }, + w: function (c) { return ['tydzień', 'tygodnia', 'tygodnie', 'tygodni'][getPolishForm(c)] }, + d: function (c) { return ['dzień', 'dnia', 'dni', 'dni'][getPolishForm(c)] }, + h: function (c) { return ['godzina', 'godziny', 'godziny', 'godzin'][getPolishForm(c)] }, + m: function (c) { return ['minuta', 'minuty', 'minuty', 'minut'][getPolishForm(c)] }, + s: function (c) { return ['sekunda', 'sekundy', 'sekundy', 'sekund'][getPolishForm(c)] }, + ms: function (c) { return ['milisekunda', 'milisekundy', 'milisekundy', 'milisekund'][getPolishForm(c)] }, + decimal: ',' }, pt: { - year: function(c) { return "ano" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return (c !== 1) ? "meses" : "mês"; }, - week: function(c) { return "semana" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "dia" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hora" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minuto" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segundo" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milissegundo" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'ano' + (c !== 1 ? 's' : '') }, + mo: function (c) { return c !== 1 ? 'meses' : 'mês' }, + w: function (c) { return 'semana' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'dia' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hora' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minuto' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segundo' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milissegundo' + (c !== 1 ? 's' : '') }, + decimal: ',' }, ru: { - year: function(c) { return ["лет", "год", "года"][getRussianForm(c)]; }, - month: function(c) { return ["месяцев", "месяц", "месяца"][getRussianForm(c)]; }, - week: function(c) { return ["недель", "неделя", "недели"][getRussianForm(c)]; }, - day: function(c) { return ["дней", "день", "дня"][getRussianForm(c)]; }, - hour: function(c) { return ["часов", "час", "часа"][getRussianForm(c)]; }, - minute: function(c) { return ["минут", "минута", "минуты"][getRussianForm(c)]; }, - second: function(c) { return ["секунд", "секунда", "секунды"][getRussianForm(c)]; }, - millisecond: function(c) { return ["миллисекунд", "миллисекунда", "миллисекунды"][getRussianForm(c)]; } + y: function (c) { return ['лет', 'год', 'года'][getSlavicForm(c)] }, + mo: function (c) { return ['месяцев', 'месяц', 'месяца'][getSlavicForm(c)] }, + w: function (c) { return ['недель', 'неделя', 'недели'][getSlavicForm(c)] }, + d: function (c) { return ['дней', 'день', 'дня'][getSlavicForm(c)] }, + h: function (c) { return ['часов', 'час', 'часа'][getSlavicForm(c)] }, + m: function (c) { return ['минут', 'минута', 'минуты'][getSlavicForm(c)] }, + s: function (c) { return ['секунд', 'секунда', 'секунды'][getSlavicForm(c)] }, + ms: function (c) { return ['миллисекунд', 'миллисекунда', 'миллисекунды'][getSlavicForm(c)] }, + decimal: ',' + }, + uk: { + y: function (c) { return ['років', 'рік', 'роки'][getSlavicForm(c)] }, + mo: function (c) { return ['місяців', 'місяць', 'місяці'][getSlavicForm(c)] }, + w: function (c) { return ['неділь', 'неділя', 'неділі'][getSlavicForm(c)] }, + d: function (c) { return ['днів', 'день', 'дні'][getSlavicForm(c)] }, + h: function (c) { return ['годин', 'година', 'години'][getSlavicForm(c)] }, + m: function (c) { return ['хвилин', 'хвилина', 'хвилини'][getSlavicForm(c)] }, + s: function (c) { return ['секунд', 'секунда', 'секунди'][getSlavicForm(c)] }, + ms: function (c) { return ['мілісекунд', 'мілісекунда', 'мілісекунди'][getSlavicForm(c)] }, + decimal: ',' }, sv: { - year: "år", - month: function(c) { return "månad" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "veck" + ((c !== 1) ? "or" : "a"); }, - day: function(c) { return "dag" + ((c !== 1) ? "ar" : ""); }, - hour: function(c) { return "timm" + ((c !== 1) ? "ar" : "e"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "er" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + y: 'år', + mo: function (c) { return 'månad' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'veck' + (c !== 1 ? 'or' : 'a') }, + d: function (c) { return 'dag' + (c !== 1 ? 'ar' : '') }, + h: function (c) { return 'timm' + (c !== 1 ? 'ar' : 'e') }, + m: function (c) { return 'minut' + (c !== 1 ? 'er' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, tr: { - year: "yıl", - month: "ay", - week: "hafta", - day: "gün", - hour: "saat", - minute: "dakika", - second: "saniye", - millisecond: "milisaniye" + y: 'yıl', + mo: 'ay', + w: 'hafta', + d: 'gün', + h: 'saat', + m: 'dakika', + s: 'saniye', + ms: 'milisaniye', + decimal: ',' }, - "zh-CN": { - year: "年", - month: "个月", - week: "周", - day: "天", - hour: "小时", - minute: "分钟", - second: "秒", - millisecond: "毫秒" + vi: { + y: 'năm', + mo: 'tháng', + w: 'tuần', + d: 'ngày', + h: 'giờ', + m: 'phút', + s: 'giây', + ms: 'mili giây', + decimal: ',' }, - "zh-TW": { - year: "年", - month: "個月", - week: "周", - day: "天", - hour: "小時", - minute: "分鐘", - second: "秒", - millisecond: "毫秒" + zh_CN: { + y: '年', + mo: '个月', + w: '周', + d: '天', + h: '小时', + m: '分钟', + s: '秒', + ms: '毫秒', + decimal: '.' + }, + zh_TW: { + y: '年', + mo: '個月', + w: '周', + d: '天', + h: '小時', + m: '分鐘', + s: '秒', + ms: '毫秒', + decimal: '.' } - }; + } - // You can create a humanizer, which returns a function with defaults + // You can create a humanizer, which returns a function with default // parameters. - function humanizer(passedOptions) { - - var result = function humanizer(ms, humanizerOptions) { - var options = extend({}, result, humanizerOptions || {}); - return doHumanization(ms, options); - }; + function humanizer (passedOptions) { + var result = function humanizer (ms, humanizerOptions) { + var options = extend({}, result, humanizerOptions || {}) + return doHumanization(ms, options) + } return extend(result, { - language: "en", - delimiter: ", ", - spacer: " ", - units: ["year", "month", "week", "day", "hour", "minute", "second"], + language: 'en', + delimiter: ', ', + spacer: ' ', + conjunction: '', + serialComma: true, + units: ['y', 'mo', 'w', 'd', 'h', 'm', 's'], languages: {}, - halfUnit: true, - round: false - }, passedOptions); - + round: false, + unitMeasures: { + y: 31557600000, + mo: 2629800000, + w: 604800000, + d: 86400000, + h: 3600000, + m: 60000, + s: 1000, + ms: 1 + } + }, passedOptions) } // The main function is just a wrapper around a default humanizer. - var defaultHumanizer = humanizer({}); - function humanizeDuration() { - return defaultHumanizer.apply(defaultHumanizer, arguments); - } + var humanizeDuration = humanizer({}) // doHumanization does the bulk of the work. - function doHumanization(ms, options) { + function doHumanization (ms, options) { + var i, len, piece // Make sure we have a positive number. // Has the nice sideffect of turning Number objects into primitives. - ms = Math.abs(ms); - - if (ms === 0) { - return "0"; - } + ms = Math.abs(ms) - var dictionary = options.languages[options.language] || languages[options.language]; + var dictionary = options.languages[options.language] || languages[options.language] if (!dictionary) { - throw new Error("No language " + dictionary + "."); + throw new Error('No language ' + dictionary + '.') } - var result = []; + var pieces = [] // Start at the top and keep removing units, bit by bit. - var unitName, unitMS, unitCount, mightBeHalfUnit; - for (var i = 0, len = options.units.length; i < len; i ++) { + var unitName, unitMS, unitCount + for (i = 0, len = options.units.length; i < len; i++) { + unitName = options.units[i] + unitMS = options.unitMeasures[unitName] - unitName = options.units[i]; - if (unitName[unitName.length - 1] === "s") { // strip plurals - unitName = unitName.substring(0, unitName.length - 1); + // What's the number of full units we can fit? + if (i + 1 === len) { + unitCount = ms / unitMS + } else { + unitCount = Math.floor(ms / unitMS) } - unitMS = UNITS[unitName]; - // If it's a half-unit interval, we're done. - if (result.length === 0 && options.halfUnit) { - mightBeHalfUnit = (ms / unitMS) * 2; - if (mightBeHalfUnit === Math.floor(mightBeHalfUnit)) { - return render(mightBeHalfUnit / 2, unitName, dictionary, options.spacer); - } + // Add the string. + pieces.push({ + unitCount: unitCount, + unitName: unitName + }) + + // Remove what we just figured out. + ms -= unitCount * unitMS + } + + var firstOccupiedUnitIndex = 0 + for (i = 0; i < pieces.length; i++) { + if (pieces[i].unitCount) { + firstOccupiedUnitIndex = i + break } + } - // What's the number of full units we can fit? - if ((i + 1) === len) { - unitCount = ms / unitMS; - if (options.round) { - unitCount = Math.round(unitCount); + if (options.round) { + var ratioToLargerUnit, previousPiece + for (i = pieces.length - 1; i >= 0; i--) { + piece = pieces[i] + piece.unitCount = Math.round(piece.unitCount) + + if (i === 0) { break } + + previousPiece = pieces[i - 1] + + ratioToLargerUnit = options.unitMeasures[previousPiece.unitName] / options.unitMeasures[piece.unitName] + if ((piece.unitCount % ratioToLargerUnit) === 0 || (options.largest && ((options.largest - 1) < (i - firstOccupiedUnitIndex)))) { + previousPiece.unitCount += piece.unitCount / ratioToLargerUnit + piece.unitCount = 0 } - } else { - unitCount = Math.floor(ms / unitMS); } + } - // Add the string. - if (unitCount) { - result.push(render(unitCount, unitName, dictionary, options.spacer)); + var result = [] + for (i = 0, pieces.length; i < len; i++) { + piece = pieces[i] + if (piece.unitCount) { + result.push(render(piece.unitCount, piece.unitName, dictionary, options)) } - // Remove what we just figured out. - ms -= unitCount * unitMS; + if (result.length === options.largest) { break } + } + if (result.length) { + if (!options.conjunction || result.length === 1) { + return result.join(options.delimiter) + } else if (result.length === 2) { + return result.join(options.conjunction) + } else if (result.length > 2) { + return result.slice(0, -1).join(options.delimiter) + (options.serialComma ? ',' : '') + options.conjunction + result.slice(-1) + } + } else { + return render(0, options.units[options.units.length - 1], dictionary, options) } + } - return result.join(options.delimiter); + function render (count, type, dictionary, options) { + var decimal + if (options.decimal === void 0) { + decimal = dictionary.decimal + } else { + decimal = options.decimal + } - } + var countStr = count.toString().replace('.', decimal) - function render(count, type, dictionary, spacer) { - var dictionaryValue = dictionary[type]; - var word; - if (typeof dictionaryValue === "function") { - word = dictionaryValue(count); + var dictionaryValue = dictionary[type] + var word + if (typeof dictionaryValue === 'function') { + word = dictionaryValue(count) } else { - word = dictionaryValue; + word = dictionaryValue } - return count + spacer + word; + + return countStr + options.spacer + word } - function extend(destination) { - var source; - for (var i = 1; i < arguments.length; i ++) { - source = arguments[i]; + function extend (destination) { + var source + for (var i = 1; i < arguments.length; i++) { + source = arguments[i] for (var prop in source) { if (source.hasOwnProperty(prop)) { - destination[prop] = source[prop]; + destination[prop] = source[prop] } } } - return destination; + return destination + } + + // Internal helper function for Czech language. + function getCzechForm (c) { + if (c === 1) { + return 0 + } else if (Math.floor(c) !== c) { + return 1 + } else if (c % 10 >= 2 && c % 10 <= 4 && c % 100 < 10) { + return 2 + } else { + return 3 + } } // Internal helper function for Polish language. - function getPolishForm(c) { + function getPolishForm (c) { if (c === 1) { - return 0; + return 0 } else if (Math.floor(c) !== c) { - return 1; - } else if (2 <= c % 10 && c % 10 <= 4 && !(10 < c % 100 && c % 100 < 20)) { - return 2; + return 1 + } else if (c % 10 >= 2 && c % 10 <= 4 && !(c % 100 > 10 && c % 100 < 20)) { + return 2 } else { - return 3; + return 3 } } - // Internal helper function for Russian language. - function getRussianForm(c) { + // Internal helper function for Russian and Ukranian languages. + function getSlavicForm (c) { if (Math.floor(c) !== c) { - return 2; - } else if (c === 0 || (c >= 5 && c <= 20) || (c % 10 >= 5 && c % 10 <= 9) || (c % 10 === 0)) { - return 0; - } else if (c === 1 || c % 10 === 1) { - return 1; + return 2 + } else if ((c % 100 >= 5 && c % 100 <= 20) || (c % 10 >= 5 && c % 10 <= 9) || c % 10 === 0) { + return 0 + } else if (c % 10 === 1) { + return 1 } else if (c > 1) { - return 2; + return 2 + } else { + return 0 + } + } + + // Internal helper function for Lithuanian language. + function getLithuanianForm (c) { + if (c === 1 || (c % 10 === 1 && c % 100 > 20)) { + return 0 + } else if (Math.floor(c) !== c || (c % 10 >= 2 && c % 100 > 20) || (c % 10 >= 2 && c % 100 < 10)) { + return 1 } else { - return 0; + return 2 } } - function getSupportedLanguages() { - var result = []; + humanizeDuration.getSupportedLanguages = function getSupportedLanguages () { + var result = [] for (var language in languages) { if (languages.hasOwnProperty(language)) { - result.push(language); + result.push(language) } } - return result; + return result } - humanizeDuration.humanizer = humanizer; - humanizeDuration.getSupportedLanguages = getSupportedLanguages; + humanizeDuration.humanizer = humanizer - if (typeof define === "function" && define.amd) { - define(function() { - return humanizeDuration; - }); - } else if (typeof module !== "undefined" && module.exports) { - module.exports = humanizeDuration; + if (typeof define === 'function' && define.amd) { + define(function () { + return humanizeDuration + }) + } else if (typeof module !== 'undefined' && module.exports) { + module.exports = humanizeDuration } else { - this.humanizeDuration = humanizeDuration; + this.humanizeDuration = humanizeDuration } - -})(); +})(); // eslint-disable-line semi diff --git a/bower_components/humanize-duration/package.json b/bower_components/humanize-duration/package.json index f9e8632..930dc3a 100644 --- a/bower_components/humanize-duration/package.json +++ b/bower_components/humanize-duration/package.json @@ -2,6 +2,7 @@ "name": "humanize-duration", "author": "Evan Hahn (http://evanhahn.com)", "contributors": [ + "Óli Tómas Freysson (https://github.com/olitomas)", "Martin Prins (https://github.com/magarcia)", "Filipi Siqueira (https://github.com/filipi777)", "Peter Rekdal Sunde (https://github.com/peters)", @@ -9,22 +10,30 @@ "Eileen Li (https://github.com/eileen3)", "Tommy Brunn (https://github.com/Nevon)", "Giovanni Pellerano (https://github.com/evilaliv3)", - "Rahma Sghaier (https://twitter.com/sghaierrahma)" + "Rahma Sghaier (https://twitter.com/sghaierrahma)", + "Evgenios Kastanias (https://github.com/evgenios)", + "Oleksii Mylotskyi (https://github.com/spalax)", + "Matthew Brandly (https://github.com/brandly)", + "Patrik Simek (https://github.com/patriksimek)", + "Toni Helminen (https://github.com/tonihelminen)", + "Vidmantas Drasutis (https://github.com/drasius2)", + "Manh Tuan (https://github.com/J2TeaM)", + "Leonard Lee (https://github.com/sheeeng)", + "Jesse Jackson (https://github.com/jsejcksn)" ], - "version": "2.8.0", + "version": "3.10.0", "description": "Convert millisecond durations to English and many other languages.", "homepage": "https://github.com/EvanHahn/HumanizeDuration.js", "main": "humanize-duration.js", "scripts": { - "test": "mocha", - "hint": "jshint humanize-duration.js" + "pretest": "standard", + "test": "mocha" }, "devDependencies": { - "coffee-script": "^1.9.2", - "csv-parse": "^0.1.1", - "jshint": "^2.7.0", - "mocha": "^2.2.4", - "ms": "^0.7.1" + "csv-parse": "^1.1.1", + "mocha": "^2.5.3", + "ms": "^0.7.1", + "standard": "^7.1.2" }, "keywords": [ "humanize", @@ -42,5 +51,13 @@ "url": "git://github.com/EvanHahn/HumanizeDuration.js.git" }, "bugs": "https://github.com/EvanHahn/HumanizeDuration.js/issues", - "license": "WTFPL" + "license": "Unlicense", + "standard": { + "globals": [ + "define", + "describe", + "it", + "before" + ] + } } diff --git a/dist/angular-timer.js b/dist/angular-timer.js index 7df63ac..f927ebb 100644 --- a/dist/angular-timer.js +++ b/dist/angular-timer.js @@ -1,12 +1,10 @@ /** - * angular-timer - v1.3.4 - 2016-05-01 9:52 PM + * angular-timer - v1.3.5 - 2017-07-23 2:18 PM * https://github.com/siddii/angular-timer * - * Copyright (c) 2016 Siddique Hameed + * Copyright (c) 2017 Siddique Hameed * Licensed MIT */ -var humanizeDuration = require("humanize-duration"); -var moment = require("moment"); var timerModule = angular.module('timer', []) .directive('timer', ['$compile', function ($compile) { return { @@ -123,7 +121,7 @@ var timerModule = angular.module('timer', []) } }); - $scope.start = $element[0].start = function () { + $scope.start = function () { $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment(); $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null; if (!angular.isNumber($scope.countdown)) { @@ -132,25 +130,49 @@ var timerModule = angular.module('timer', []) resetTimeout(); tick(); $scope.isRunning = true; + $scope.$emit('timer-started', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.resume = $element[0].resume = function () { + $scope.resume = function () { resetTimeout(); if ($scope.countdownattr) { $scope.countdown += 1; } $scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime)))); + $scope.endTime += moment().diff(moment($scope.stoppedTime)); tick(); $scope.isRunning = true; + $scope.$emit('timer-started', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.stop = $scope.pause = $element[0].stop = $element[0].pause = function () { + $scope.stop = $scope.pause = function () { var timeoutId = $scope.timeoutId; $scope.clear(); - $scope.$emit('timer-stopped', {timeoutId: timeoutId, millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days}); + $scope.$emit('timer-stopped', { + timeoutId: timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; - $scope.clear = $element[0].clear = function () { + $scope.clear = function () { // same as stop but without the event being triggered $scope.stoppedTime = moment(); resetTimeout(); @@ -158,7 +180,7 @@ var timerModule = angular.module('timer', []) $scope.isRunning = false; }; - $scope.reset = $element[0].reset = function () { + $scope.reset = function () { $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment(); $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null; $scope.countdown = angular.isNumber($scope.countdownattr) && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined; @@ -166,6 +188,14 @@ var timerModule = angular.module('timer', []) tick(); $scope.isRunning = false; $scope.clear(); + $scope.$emit('timer-reseted', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); }; $element.bind('$destroy', function () { @@ -258,18 +288,15 @@ var timerModule = angular.module('timer', []) if ($scope.countdownattr) { $scope.millis = $scope.countdownattr * 1000; - $scope.addCDSeconds = $element[0].addCDSeconds = function (extraSeconds) { + $scope.addCDSeconds = function (extraSeconds) { $scope.countdown += extraSeconds; - $scope.$digest(); if (!$scope.isRunning) { $scope.start(); } }; $scope.$on('timer-add-cd-seconds', function (e, extraSeconds) { - $timeout(function () { - $scope.addCDSeconds(extraSeconds); - }); + $scope.addCDSeconds(extraSeconds); }); $scope.$on('timer-set-countdown-seconds', function (e, countdownSeconds) { @@ -315,11 +342,20 @@ var timerModule = angular.module('timer', []) //We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5 $scope.timeoutId = setTimeout(function () { - tick(); - $scope.$digest(); + tick(); + // since you choose not to use $timeout, at least preserve angular cycle two way data binding + // by calling $scope.$apply() instead of $scope.$digest() + $scope.$apply(); }, $scope.interval - adjustment); - $scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis, timerElement: $element[0]}); + $scope.$emit('timer-tick', { + timeoutId: $scope.timeoutId, + millis: $scope.millis, + seconds: $scope.seconds, + minutes: $scope.minutes, + hours: $scope.hours, + days: $scope.days + }); if ($scope.countdown > 0) { $scope.countdown--; @@ -346,7 +382,50 @@ var timerModule = angular.module('timer', []) } }] }; - }]); + }]) + .directive('timerControls', function() { + return { + restrict: 'EA', + scope: true, + controller: ['$scope', function($scope) { + $scope.timerStatus = "reset"; + $scope.$on('timer-started', function() { + $scope.timerStatus = "started"; + }); + $scope.$on('timer-stopped', function() { + $scope.timerStatus = "stopped"; + }); + $scope.$on('timer-reset', function() { + $scope.timerStatus = "reset"; + }); + $scope.timerStart = function() { + $scope.$broadcast('timer-start'); + }; + $scope.timerStop = function() { + $scope.$broadcast('timer-stop'); + }; + $scope.timerResume = function() { + $scope.$broadcast('timer-resume'); + }; + $scope.timerToggle = function() { + switch ($scope.timerStatus) { + case "started": + $scope.timerStop(); + break; + case "stopped": + $scope.timerResume(); + break; + case "reset": + $scope.timerStart(); + break; + } + }; + $scope.timerAddCDSeconds = function(extraSeconds) { + $scope.$broadcast('timer-add-cd-seconds', extraSeconds); + }; + }] + }; + }); /* commonjs package manager support (eg componentjs) */ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){ @@ -376,8 +455,9 @@ app.factory('I18nService', function() { this.language = this.fallback; } - //moment init - moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive + // It should be handle by the user's application itself, and not inside the directive + // moment init + // moment.locale(this.language); //human duration init, using it because momentjs does not allow accurate time ( // momentJS: a few moment ago, human duration : 4 seconds ago @@ -399,13 +479,13 @@ app.factory('I18nService', function() { if (typeof this.timeHumanizer != 'undefined'){ time = { - 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["milliseconds"] }), - 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["seconds"] }), - 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["minutes", "seconds"] }) , - 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["hours", "minutes", "seconds"] }) , - 'days' : this.timeHumanizer(diffFromAlarm, { units: ["days", "hours", "minutes", "seconds"] }) , - 'months' : this.timeHumanizer(diffFromAlarm, { units: ["months", "days", "hours", "minutes", "seconds"] }) , - 'years' : this.timeHumanizer(diffFromAlarm, { units: ["years", "months", "days", "hours", "minutes", "seconds"] }) + 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["ms"] }), + 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["s"] }), + 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["m", "s"] }) , + 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["h", "m", "s"] }) , + 'days' : this.timeHumanizer(diffFromAlarm, { units: ["d", "h", "m", "s"] }) , + 'months' : this.timeHumanizer(diffFromAlarm, { units: ["mo", "d", "h", "m", "s"] }) , + 'years' : this.timeHumanizer(diffFromAlarm, { units: ["y", "mo", "d", "h", "m", "s"] }) }; } else { diff --git a/dist/angular-timer.min.js b/dist/angular-timer.min.js index 32f3c57..5d22c85 100644 --- a/dist/angular-timer.min.js +++ b/dist/angular-timer.min.js @@ -1,8 +1,8 @@ /** - * angular-timer - v1.3.4 - 2016-05-01 9:52 PM + * angular-timer - v1.3.5 - 2017-07-23 2:18 PM * https://github.com/siddii/angular-timer * - * Copyright (c) 2016 Siddique Hameed + * Copyright (c) 2017 Siddique Hameed * Licensed MIT */ -var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",fallback:"@?",maxTimeUnit:"=",seconds:"=?",minutes:"=?",hours:"=?",days:"=?",months:"=?",years:"=?",secondsS:"=?",minutesS:"=?",hoursS:"=?",daysS:"=?",monthsS:"=?",yearsS:"=?"},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate","progressBarService",function(b,c,d,e,f,g,h){function i(){b.timeoutId&&clearTimeout(b.timeoutId)}function j(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=k.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.fallback=b.fallback||"en",b.$watch("language",function(a){void 0!==a&&k.init(a,b.fallback)});var k=new f;k.init(b.language,b.fallback),b.displayProgressBar=0,b.displayProgressActive="active",c.append(0===c.html().trim().length?a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b):a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.$watch("endTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=c[0].start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,angular.isNumber(b.countdown)||(b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),i(),l(),b.isRunning=!0},b.resume=c[0].resume=function(){i(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),l(),b.isRunning=!0},b.stop=b.pause=c[0].stop=c[0].pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=c[0].clear=function(){b.stoppedTime=moment(),i(),b.timeoutId=null,b.isRunning=!1},b.reset=c[0].reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,i(),l(),b.isRunning=!1,b.clear()},c.bind("$destroy",function(){i(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=c[0].addCDSeconds=function(a){b.countdown+=a,b.$digest(),b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){e(function(){b.addCDSeconds(c)})}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,j()})):b.millis=0,j();var l=function m(){var a=null;b.millis=moment().diff(b.startTime);var d=b.millis%1e3;return b.endTimeAttr&&(a=b.endTimeAttr,b.millis=moment(b.endTime).diff(moment()),d=b.interval-b.millis%1e3),b.countdownattr&&(a=b.countdownattr,b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,j(),void(b.finishCallback&&b.$eval(b.finishCallback))):(j(),b.timeoutId=setTimeout(function(){m(),b.$digest()},b.interval-d),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis,timerElement:c[0]}),b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback)),void(null!==a&&(b.progressBar=h.calculateProgressBar(b.startTime,b.millis,b.endTime,b.countdownattr),100===b.progressBar&&(b.displayProgressActive=""))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule);var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.fallback="en",a.prototype.timeHumanizer={},a.prototype.init=function(a,b){var c=humanizeDuration.getSupportedLanguages();this.fallback=void 0!==b?b:"en",-1===c.indexOf(b)&&(this.fallback="en"),this.language=a,-1===c.indexOf(a)&&(this.language=this.fallback),moment.locale(this.language),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["milliseconds"]}),seconds:this.timeHumanizer(b,{units:["seconds"]}),minutes:this.timeHumanizer(b,{units:["minutes","seconds"]}),hours:this.timeHumanizer(b,{units:["hours","minutes","seconds"]}),days:this.timeHumanizer(b,{units:["days","hours","minutes","seconds"]}),months:this.timeHumanizer(b,{units:["months","days","hours","minutes","seconds"]}),years:this.timeHumanizer(b,{units:["years","months","days","hours","minutes","seconds"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a});var app=angular.module("timer");app.factory("progressBarService",function(){var a=function(){};return a.prototype.calculateProgressBar=function(a,b,c,d){var e,f,g=0;return b/=1e3,null!==c?(e=moment(c),f=e.diff(a,"seconds"),g=100*b/f):g=100*b/d,g=100-g,g=Math.round(10*g)/10,g>100&&(g=100),g},new a}); \ No newline at end of file +var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",fallback:"@?",maxTimeUnit:"=",seconds:"=?",minutes:"=?",hours:"=?",days:"=?",months:"=?",years:"=?",secondsS:"=?",minutesS:"=?",hoursS:"=?",daysS:"=?",monthsS:"=?",yearsS:"=?"},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate","progressBarService",function(b,c,d,e,f,g,h){function i(){b.timeoutId&&clearTimeout(b.timeoutId)}function j(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=k.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.fallback=b.fallback||"en",b.$watch("language",function(a,c){void 0!==a&&k.init(a,b.fallback)});var k=new f;k.init(b.language,b.fallback),b.displayProgressBar=0,b.displayProgressActive="active",0===c.html().trim().length?c.append(a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b)):c.append(a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.$watch("endTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,angular.isNumber(b.countdown)||(b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),i(),l(),b.isRunning=!0,b.$emit("timer-started",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.resume=function(){i(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),l(),b.isRunning=!0,b.$emit("timer-started",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.stop=b.pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=function(){b.stoppedTime=moment(),i(),b.timeoutId=null,b.isRunning=!1},b.reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,i(),l(),b.isRunning=!1,b.clear(),b.$emit("timer-reseted",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},c.bind("$destroy",function(){i(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=function(a){b.countdown+=a,b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){b.addCDSeconds(c)}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,j()})):b.millis=0,j();var l=function m(){var a=null;b.millis=moment().diff(b.startTime);var c=b.millis%1e3;return b.endTimeAttr&&(a=b.endTimeAttr,b.millis=moment(b.endTime).diff(moment()),c=b.interval-b.millis%1e3),b.countdownattr&&(a=b.countdownattr,b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,j(),void(b.finishCallback&&b.$eval(b.finishCallback))):(j(),b.timeoutId=setTimeout(function(){m(),b.$apply()},b.interval-c),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days}),b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback)),void(null!==a&&(b.progressBar=h.calculateProgressBar(b.startTime,b.millis,b.endTime,b.countdownattr),100===b.progressBar&&(b.displayProgressActive=""))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]).directive("timerControls",function(){return{restrict:"EA",scope:!0,controller:["$scope",function(a){a.timerStatus="reset",a.$on("timer-started",function(){a.timerStatus="started"}),a.$on("timer-stopped",function(){a.timerStatus="stopped"}),a.$on("timer-reset",function(){a.timerStatus="reset"}),a.timerStart=function(){a.$broadcast("timer-start")},a.timerStop=function(){a.$broadcast("timer-stop")},a.timerResume=function(){a.$broadcast("timer-resume")},a.timerToggle=function(){switch(a.timerStatus){case"started":a.timerStop();break;case"stopped":a.timerResume();break;case"reset":a.timerStart()}},a.timerAddCDSeconds=function(b){a.$broadcast("timer-add-cd-seconds",b)}}]}});"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule);var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.fallback="en",a.prototype.timeHumanizer={},a.prototype.init=function(a,b){var c=humanizeDuration.getSupportedLanguages();this.fallback=void 0!==b?b:"en",-1===c.indexOf(b)&&(this.fallback="en"),this.language=a,-1===c.indexOf(a)&&(this.language=this.fallback),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["ms"]}),seconds:this.timeHumanizer(b,{units:["s"]}),minutes:this.timeHumanizer(b,{units:["m","s"]}),hours:this.timeHumanizer(b,{units:["h","m","s"]}),days:this.timeHumanizer(b,{units:["d","h","m","s"]}),months:this.timeHumanizer(b,{units:["mo","d","h","m","s"]}),years:this.timeHumanizer(b,{units:["y","mo","d","h","m","s"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a});var app=angular.module("timer");app.factory("progressBarService",function(){var a=function(){};return a.prototype.calculateProgressBar=function(a,b,c,d){var e,f,g=0;return b/=1e3,null!==c?(e=moment(c),f=e.diff(a,"seconds"),g=100*b/f):g=100*b/d,g=100-g,g=Math.round(10*g)/10,g>100&&(g=100),g},new a}); \ No newline at end of file diff --git a/dist/assets/js/angular-timer-all.min.js b/dist/assets/js/angular-timer-all.min.js index e019014..057624e 100644 --- a/dist/assets/js/angular-timer-all.min.js +++ b/dist/assets/js/angular-timer-all.min.js @@ -1,389 +1,561 @@ /** - * angular-timer - v1.3.4 - 2016-05-01 9:52 PM + * angular-timer - v1.3.5 - 2017-07-23 2:18 PM * https://github.com/siddii/angular-timer * - * Copyright (c) 2016 Siddique Hameed + * Copyright (c) 2017 Siddique Hameed * Licensed MIT */ -var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",fallback:"@?",maxTimeUnit:"=",seconds:"=?",minutes:"=?",hours:"=?",days:"=?",months:"=?",years:"=?",secondsS:"=?",minutesS:"=?",hoursS:"=?",daysS:"=?",monthsS:"=?",yearsS:"=?"},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate","progressBarService",function(b,c,d,e,f,g,h){function i(){b.timeoutId&&clearTimeout(b.timeoutId)}function j(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=k.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.fallback=b.fallback||"en",b.$watch("language",function(a){void 0!==a&&k.init(a,b.fallback)});var k=new f;k.init(b.language,b.fallback),b.displayProgressBar=0,b.displayProgressActive="active",c.append(0===c.html().trim().length?a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b):a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.$watch("endTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=c[0].start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,angular.isNumber(b.countdown)||(b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),i(),l(),b.isRunning=!0},b.resume=c[0].resume=function(){i(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),l(),b.isRunning=!0},b.stop=b.pause=c[0].stop=c[0].pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=c[0].clear=function(){b.stoppedTime=moment(),i(),b.timeoutId=null,b.isRunning=!1},b.reset=c[0].reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,i(),l(),b.isRunning=!1,b.clear()},c.bind("$destroy",function(){i(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=c[0].addCDSeconds=function(a){b.countdown+=a,b.$digest(),b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){e(function(){b.addCDSeconds(c)})}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,j()})):b.millis=0,j();var l=function m(){var a=null;b.millis=moment().diff(b.startTime);var d=b.millis%1e3;return b.endTimeAttr&&(a=b.endTimeAttr,b.millis=moment(b.endTime).diff(moment()),d=b.interval-b.millis%1e3),b.countdownattr&&(a=b.countdownattr,b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,j(),void(b.finishCallback&&b.$eval(b.finishCallback))):(j(),b.timeoutId=setTimeout(function(){m(),b.$digest()},b.interval-d),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis,timerElement:c[0]}),b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback)),void(null!==a&&(b.progressBar=h.calculateProgressBar(b.startTime,b.millis,b.endTime,b.countdownattr),100===b.progressBar&&(b.displayProgressActive=""))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule);var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.fallback="en",a.prototype.timeHumanizer={},a.prototype.init=function(a,b){var c=humanizeDuration.getSupportedLanguages();this.fallback=void 0!==b?b:"en",-1===c.indexOf(b)&&(this.fallback="en"),this.language=a,-1===c.indexOf(a)&&(this.language=this.fallback),moment.locale(this.language),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["milliseconds"]}),seconds:this.timeHumanizer(b,{units:["seconds"]}),minutes:this.timeHumanizer(b,{units:["minutes","seconds"]}),hours:this.timeHumanizer(b,{units:["hours","minutes","seconds"]}),days:this.timeHumanizer(b,{units:["days","hours","minutes","seconds"]}),months:this.timeHumanizer(b,{units:["months","days","hours","minutes","seconds"]}),years:this.timeHumanizer(b,{units:["years","months","days","hours","minutes","seconds"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a});var app=angular.module("timer");app.factory("progressBarService",function(){var a=function(){};return a.prototype.calculateProgressBar=function(a,b,c,d){var e,f,g=0;return b/=1e3,null!==c?(e=moment(c),f=e.diff(a,"seconds"),g=100*b/f):g=100*b/d,g=100-g,g=Math.round(10*g)/10,g>100&&(g=100),g},new a}); +var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",fallback:"@?",maxTimeUnit:"=",seconds:"=?",minutes:"=?",hours:"=?",days:"=?",months:"=?",years:"=?",secondsS:"=?",minutesS:"=?",hoursS:"=?",daysS:"=?",monthsS:"=?",yearsS:"=?"},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate","progressBarService",function(b,c,d,e,f,g,h){function i(){b.timeoutId&&clearTimeout(b.timeoutId)}function j(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=k.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.fallback=b.fallback||"en",b.$watch("language",function(a,c){void 0!==a&&k.init(a,b.fallback)});var k=new f;k.init(b.language,b.fallback),b.displayProgressBar=0,b.displayProgressActive="active",0===c.html().trim().length?c.append(a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b)):c.append(a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.$watch("endTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,angular.isNumber(b.countdown)||(b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),i(),l(),b.isRunning=!0,b.$emit("timer-started",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.resume=function(){i(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),l(),b.isRunning=!0,b.$emit("timer-started",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.stop=b.pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=function(){b.stoppedTime=moment(),i(),b.timeoutId=null,b.isRunning=!1},b.reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=angular.isNumber(b.countdownattr)&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,i(),l(),b.isRunning=!1,b.clear(),b.$emit("timer-reseted",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},c.bind("$destroy",function(){i(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=function(a){b.countdown+=a,b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){b.addCDSeconds(c)}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,j()})):b.millis=0,j();var l=function m(){var a=null;b.millis=moment().diff(b.startTime);var c=b.millis%1e3;return b.endTimeAttr&&(a=b.endTimeAttr,b.millis=moment(b.endTime).diff(moment()),c=b.interval-b.millis%1e3),b.countdownattr&&(a=b.countdownattr,b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,j(),void(b.finishCallback&&b.$eval(b.finishCallback))):(j(),b.timeoutId=setTimeout(function(){m(),b.$apply()},b.interval-c),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days}),b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback)),void(null!==a&&(b.progressBar=h.calculateProgressBar(b.startTime,b.millis,b.endTime,b.countdownattr),100===b.progressBar&&(b.displayProgressActive=""))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]).directive("timerControls",function(){return{restrict:"EA",scope:!0,controller:["$scope",function(a){a.timerStatus="reset",a.$on("timer-started",function(){a.timerStatus="started"}),a.$on("timer-stopped",function(){a.timerStatus="stopped"}),a.$on("timer-reset",function(){a.timerStatus="reset"}),a.timerStart=function(){a.$broadcast("timer-start")},a.timerStop=function(){a.$broadcast("timer-stop")},a.timerResume=function(){a.$broadcast("timer-resume")},a.timerToggle=function(){switch(a.timerStatus){case"started":a.timerStop();break;case"stopped":a.timerResume();break;case"reset":a.timerStart()}},a.timerAddCDSeconds=function(b){a.$broadcast("timer-add-cd-seconds",b)}}]}});"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule);var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.fallback="en",a.prototype.timeHumanizer={},a.prototype.init=function(a,b){var c=humanizeDuration.getSupportedLanguages();this.fallback=void 0!==b?b:"en",-1===c.indexOf(b)&&(this.fallback="en"),this.language=a,-1===c.indexOf(a)&&(this.language=this.fallback),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["ms"]}),seconds:this.timeHumanizer(b,{units:["s"]}),minutes:this.timeHumanizer(b,{units:["m","s"]}),hours:this.timeHumanizer(b,{units:["h","m","s"]}),days:this.timeHumanizer(b,{units:["d","h","m","s"]}),months:this.timeHumanizer(b,{units:["mo","d","h","m","s"]}),years:this.timeHumanizer(b,{units:["y","mo","d","h","m","s"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a});var app=angular.module("timer");app.factory("progressBarService",function(){var a=function(){};return a.prototype.calculateProgressBar=function(a,b,c,d){var e,f,g=0;return b/=1e3,null!==c?(e=moment(c),f=e.diff(a,"seconds"),g=100*b/f):g=100*b/d,g=100-g,g=Math.round(10*g)/10,g>100&&(g=100),g},new a}); // HumanizeDuration.js - http://git.io/j0HgmQ -(function() { - - var UNITS = { - year: 31557600000, - month: 2629800000, - week: 604800000, - day: 86400000, - hour: 3600000, - minute: 60000, - second: 1000, - millisecond: 1 - }; - +;(function () { var languages = { ar: { - year: function(c) { return ((c === 1) ? "سنة" : "سنوات"); }, - month: function(c) { return ((c === 1) ? "شهر" : "أشهر"); }, - week: function(c) { return ((c === 1) ? "أسبوع" : "أسابيع"); }, - day: function(c) { return ((c === 1) ? "يوم" : "أيام"); }, - hour: function(c) { return ((c === 1) ? "ساعة" : "ساعات"); }, - minute: function(c) { return ((c === 1) ? "دقيقة" : "دقائق"); }, - second: function(c) { return ((c === 1) ? "ثانية" : "ثواني"); }, - millisecond: function(c) { return ((c === 1) ? "جزء من الثانية" : "أجزاء من الثانية"); } + y: function (c) { return c === 1 ? 'سنة' : 'سنوات' }, + mo: function (c) { return c === 1 ? 'شهر' : 'أشهر' }, + w: function (c) { return c === 1 ? 'أسبوع' : 'أسابيع' }, + d: function (c) { return c === 1 ? 'يوم' : 'أيام' }, + h: function (c) { return c === 1 ? 'ساعة' : 'ساعات' }, + m: function (c) { return c === 1 ? 'دقيقة' : 'دقائق' }, + s: function (c) { return c === 1 ? 'ثانية' : 'ثواني' }, + ms: function (c) { return c === 1 ? 'جزء من الثانية' : 'أجزاء من الثانية' }, + decimal: ',' }, ca: { - year: function(c) { return "any" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "mes" + ((c !== 1) ? "os" : ""); }, - week: function(c) { return "setman" + ((c !== 1) ? "es" : "a"); }, - day: function(c) { return "di" + ((c !== 1) ? "es" : "a"); }, - hour: function(c) { return "hor" + ((c !== 1) ? "es" : "a"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segon" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milisegon" + ((c !== 1) ? "s" : "" ); } + y: function (c) { return 'any' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'os' : '') }, + w: function (c) { return 'setman' + (c !== 1 ? 'es' : 'a') }, + d: function (c) { return 'di' + (c !== 1 ? 'es' : 'a') }, + h: function (c) { return 'hor' + (c !== 1 ? 'es' : 'a') }, + m: function (c) { return 'minut' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segon' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milisegon' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + cs: { + y: function (c) { return ['rok', 'roku', 'roky', 'let'][getCzechForm(c)] }, + mo: function (c) { return ['měsíc', 'měsíce', 'měsíce', 'měsíců'][getCzechForm(c)] }, + w: function (c) { return ['týden', 'týdne', 'týdny', 'týdnů'][getCzechForm(c)] }, + d: function (c) { return ['den', 'dne', 'dny', 'dní'][getCzechForm(c)] }, + h: function (c) { return ['hodina', 'hodiny', 'hodiny', 'hodin'][getCzechForm(c)] }, + m: function (c) { return ['minuta', 'minuty', 'minuty', 'minut'][getCzechForm(c)] }, + s: function (c) { return ['sekunda', 'sekundy', 'sekundy', 'sekund'][getCzechForm(c)] }, + ms: function (c) { return ['milisekunda', 'milisekundy', 'milisekundy', 'milisekund'][getCzechForm(c)] }, + decimal: ',' }, da: { - year: "år", - month: function(c) { return "måned" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "uge" + ((c !== 1) ? "r" : ""); }, - day: function(c) { return "dag" + ((c !== 1) ? "e" : ""); }, - hour: function(c) { return "time" + ((c !== 1) ? "r" : ""); }, - minute: function(c) { return "minut" + ((c !== 1) ? "ter" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + y: 'år', + mo: function (c) { return 'måned' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'uge' + (c !== 1 ? 'r' : '') }, + d: function (c) { return 'dag' + (c !== 1 ? 'e' : '') }, + h: function (c) { return 'time' + (c !== 1 ? 'r' : '') }, + m: function (c) { return 'minut' + (c !== 1 ? 'ter' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, de: { - year: function(c) { return "Jahr" + ((c !== 1) ? "e" : ""); }, - month: function(c) { return "Monat" + ((c !== 1) ? "e" : ""); }, - week: function(c) { return "Woche" + ((c !== 1) ? "n" : ""); }, - day: function(c) { return "Tag" + ((c !== 1) ? "e" : ""); }, - hour: function(c) { return "Stunde" + ((c !== 1) ? "n" : ""); }, - minute: function(c) { return "Minute" + ((c !== 1) ? "n" : ""); }, - second: function(c) { return "Sekunde" + ((c !== 1) ? "n" : ""); }, - millisecond: function(c) { return "Millisekunde" + ((c !== 1) ? "n" : ""); } + y: function (c) { return 'Jahr' + (c !== 1 ? 'e' : '') }, + mo: function (c) { return 'Monat' + (c !== 1 ? 'e' : '') }, + w: function (c) { return 'Woche' + (c !== 1 ? 'n' : '') }, + d: function (c) { return 'Tag' + (c !== 1 ? 'e' : '') }, + h: function (c) { return 'Stunde' + (c !== 1 ? 'n' : '') }, + m: function (c) { return 'Minute' + (c !== 1 ? 'n' : '') }, + s: function (c) { return 'Sekunde' + (c !== 1 ? 'n' : '') }, + ms: function (c) { return 'Millisekunde' + (c !== 1 ? 'n' : '') }, + decimal: ',' }, en: { - year: function(c) { return "year" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "month" + ((c !== 1) ? "s" : ""); }, - week: function(c) { return "week" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "day" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hour" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minute" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "second" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "millisecond" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'year' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'month' + (c !== 1 ? 's' : '') }, + w: function (c) { return 'week' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'day' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hour' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minute' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'second' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'millisecond' + (c !== 1 ? 's' : '') }, + decimal: '.' }, es: { - year: function(c) { return "año" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return "mes" + ((c !== 1) ? "es" : ""); }, - week: function(c) { return "semana" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "día" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hora" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minuto" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segundo" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milisegundo" + ((c !== 1) ? "s" : "" ); } + y: function (c) { return 'año' + (c !== 1 ? 's' : '') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'es' : '') }, + w: function (c) { return 'semana' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'día' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hora' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minuto' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segundo' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milisegundo' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + fi: { + y: function (c) { return c === 1 ? 'vuosi' : 'vuotta' }, + mo: function (c) { return c === 1 ? 'kuukausi' : 'kuukautta' }, + w: function (c) { return 'viikko' + (c !== 1 ? 'a' : '') }, + d: function (c) { return 'päivä' + (c !== 1 ? 'ä' : '') }, + h: function (c) { return 'tunti' + (c !== 1 ? 'a' : '') }, + m: function (c) { return 'minuutti' + (c !== 1 ? 'a' : '') }, + s: function (c) { return 'sekunti' + (c !== 1 ? 'a' : '') }, + ms: function (c) { return 'millisekunti' + (c !== 1 ? 'a' : '') }, + decimal: ',' }, fr: { - year: function(c) { return "an" + ((c !== 1) ? "s" : ""); }, - month: "mois", - week: function(c) { return "semaine" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "jour" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "heure" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minute" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "seconde" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milliseconde" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'an' + (c !== 1 ? 's' : '') }, + mo: 'mois', + w: function (c) { return 'semaine' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'jour' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'heure' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minute' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'seconde' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milliseconde' + (c !== 1 ? 's' : '') }, + decimal: ',' + }, + gr: { + y: function (c) { return c === 1 ? 'χρόνος' : 'χρόνια' }, + mo: function (c) { return c === 1 ? 'μήνας' : 'μήνες' }, + w: function (c) { return c === 1 ? 'εβδομάδα' : 'εβδομάδες' }, + d: function (c) { return c === 1 ? 'μέρα' : 'μέρες' }, + h: function (c) { return c === 1 ? 'ώρα' : 'ώρες' }, + m: function (c) { return c === 1 ? 'λεπτό' : 'λεπτά' }, + s: function (c) { return c === 1 ? 'δευτερόλεπτο' : 'δευτερόλεπτα' }, + ms: function (c) { return c === 1 ? 'χιλιοστό του δευτερολέπτου' : 'χιλιοστά του δευτερολέπτου' }, + decimal: ',' }, hu: { - year: "év", - month: "hónap", - week: "hét", - day: "nap", - hour: "óra", - minute: "perc", - second: "másodperc", - millisecond: "ezredmásodperc" + y: 'év', + mo: 'hónap', + w: 'hét', + d: 'nap', + h: 'óra', + m: 'perc', + s: 'másodperc', + ms: 'ezredmásodperc', + decimal: ',' + }, + id: { + y: 'tahun', + mo: 'bulan', + w: 'minggu', + d: 'hari', + h: 'jam', + m: 'menit', + s: 'detik', + ms: 'milidetik', + decimal: '.' + }, + is: { + y: 'ár', + mo: function (c) { return 'mánuð' + (c !== 1 ? 'ir' : 'ur') }, + w: function (c) { return 'vik' + (c !== 1 ? 'ur' : 'a') }, + d: function (c) { return 'dag' + (c !== 1 ? 'ar' : 'ur') }, + h: function (c) { return 'klukkutím' + (c !== 1 ? 'ar' : 'i') }, + m: function (c) { return 'mínút' + (c !== 1 ? 'ur' : 'a') }, + s: function (c) { return 'sekúnd' + (c !== 1 ? 'ur' : 'a') }, + ms: function (c) { return 'millisekúnd' + (c !== 1 ? 'ur' : 'a') }, + decimal: '.' }, it: { - year: function(c) { return "ann" + ((c !== 1) ? "i" : "o"); }, - month: function(c) { return "mes" + ((c !== 1) ? "i" : "e"); }, - week: function(c) { return "settiman" + ((c !== 1) ? "e" : "a"); }, - day: function(c) { return "giorn" + ((c !== 1) ? "i" : "o"); }, - hour: function(c) { return "or" + ((c !== 1) ? "e" : "a"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "i" : "o"); }, - second: function(c) { return "second" + ((c !== 1) ? "i" : "o"); }, - millisecond: function(c) { return "millisecond" + ((c !== 1) ? "i" : "o" ); } + y: function (c) { return 'ann' + (c !== 1 ? 'i' : 'o') }, + mo: function (c) { return 'mes' + (c !== 1 ? 'i' : 'e') }, + w: function (c) { return 'settiman' + (c !== 1 ? 'e' : 'a') }, + d: function (c) { return 'giorn' + (c !== 1 ? 'i' : 'o') }, + h: function (c) { return 'or' + (c !== 1 ? 'e' : 'a') }, + m: function (c) { return 'minut' + (c !== 1 ? 'i' : 'o') }, + s: function (c) { return 'second' + (c !== 1 ? 'i' : 'o') }, + ms: function (c) { return 'millisecond' + (c !== 1 ? 'i' : 'o') }, + decimal: ',' }, ja: { - year: "年", - month: "月", - week: "週", - day: "日", - hour: "時間", - minute: "分", - second: "秒", - millisecond: "ミリ秒" + y: '年', + mo: '月', + w: '週', + d: '日', + h: '時間', + m: '分', + s: '秒', + ms: 'ミリ秒', + decimal: '.' }, ko: { - year: "년", - month: "개월", - week: "주일", - day: "일", - hour: "시간", - minute: "분", - second: "초", - millisecond: "밀리 초" + y: '년', + mo: '개월', + w: '주일', + d: '일', + h: '시간', + m: '분', + s: '초', + ms: '밀리 초', + decimal: '.' + }, + lt: { + y: function (c) { return ((c % 10 === 0) || (c % 100 >= 10 && c % 100 <= 20)) ? 'metų' : 'metai' }, + mo: function (c) { return ['mėnuo', 'mėnesiai', 'mėnesių'][getLithuanianForm(c)] }, + w: function (c) { return ['savaitė', 'savaitės', 'savaičių'][getLithuanianForm(c)] }, + d: function (c) { return ['diena', 'dienos', 'dienų'][getLithuanianForm(c)] }, + h: function (c) { return ['valanda', 'valandos', 'valandų'][getLithuanianForm(c)] }, + m: function (c) { return ['minutė', 'minutės', 'minučių'][getLithuanianForm(c)] }, + s: function (c) { return ['sekundė', 'sekundės', 'sekundžių'][getLithuanianForm(c)] }, + ms: function (c) { return ['milisekundė', 'milisekundės', 'milisekundžių'][getLithuanianForm(c)] }, + decimal: ',' + }, + ms: { + y: 'tahun', + mo: 'bulan', + w: 'minggu', + d: 'hari', + h: 'jam', + m: 'minit', + s: 'saat', + ms: 'milisaat', + decimal: '.' }, nl: { - year: "jaar", - month: function(c) { return (c === 1) ? "maand" : "maanden"; }, - week: function(c) { return (c === 1) ? "week" : "weken"; }, - day: function(c) { return (c === 1) ? "dag" : "dagen"; }, - hour: "uur", - minute: function(c) { return (c === 1) ? "minuut" : "minuten"; }, - second: function(c) { return (c === 1) ? "seconde" : "seconden"; }, - millisecond: function(c) { return (c === 1) ? "milliseconde" : "milliseconden"; } + y: 'jaar', + mo: function (c) { return c === 1 ? 'maand' : 'maanden' }, + w: function (c) { return c === 1 ? 'week' : 'weken' }, + d: function (c) { return c === 1 ? 'dag' : 'dagen' }, + h: 'uur', + m: function (c) { return c === 1 ? 'minuut' : 'minuten' }, + s: function (c) { return c === 1 ? 'seconde' : 'seconden' }, + ms: function (c) { return c === 1 ? 'milliseconde' : 'milliseconden' }, + decimal: ',' }, - nob: { - year: "år", - month: function(c) { return "måned" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "uke" + ((c !== 1) ? "r" : ""); }, - day: function(c) { return "dag" + ((c !== 1) ? "er" : ""); }, - hour: function(c) { return "time" + ((c !== 1) ? "r" : ""); }, - minute: function(c) { return "minutt" + ((c !== 1) ? "er" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + no: { + y: 'år', + mo: function (c) { return 'måned' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'uke' + (c !== 1 ? 'r' : '') }, + d: function (c) { return 'dag' + (c !== 1 ? 'er' : '') }, + h: function (c) { return 'time' + (c !== 1 ? 'r' : '') }, + m: function (c) { return 'minutt' + (c !== 1 ? 'er' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, pl: { - year: function(c) { return ["rok", "roku", "lata", "lat"][getPolishForm(c)]; }, - month: function(c) { return ["miesiąc", "miesiąca", "miesiące", "miesięcy"][getPolishForm(c)]; }, - week: function(c) { return ["tydzień", "tygodnia", "tygodnie", "tygodni"][getPolishForm(c)]; }, - day: function(c) { return ["dzień", "dnia", "dni", "dni"][getPolishForm(c)]; }, - hour: function(c) { return ["godzina", "godziny", "godziny", "godzin"][getPolishForm(c)]; }, - minute: function(c) { return ["minuta", "minuty", "minuty", "minut"][getPolishForm(c)]; }, - second: function(c) { return ["sekunda", "sekundy", "sekundy", "sekund"][getPolishForm(c)]; }, - millisecond: function(c) { return ["milisekunda", "milisekundy", "milisekundy", "milisekund"][getPolishForm(c)]; } + y: function (c) { return ['rok', 'roku', 'lata', 'lat'][getPolishForm(c)] }, + mo: function (c) { return ['miesiąc', 'miesiąca', 'miesiące', 'miesięcy'][getPolishForm(c)] }, + w: function (c) { return ['tydzień', 'tygodnia', 'tygodnie', 'tygodni'][getPolishForm(c)] }, + d: function (c) { return ['dzień', 'dnia', 'dni', 'dni'][getPolishForm(c)] }, + h: function (c) { return ['godzina', 'godziny', 'godziny', 'godzin'][getPolishForm(c)] }, + m: function (c) { return ['minuta', 'minuty', 'minuty', 'minut'][getPolishForm(c)] }, + s: function (c) { return ['sekunda', 'sekundy', 'sekundy', 'sekund'][getPolishForm(c)] }, + ms: function (c) { return ['milisekunda', 'milisekundy', 'milisekundy', 'milisekund'][getPolishForm(c)] }, + decimal: ',' }, pt: { - year: function(c) { return "ano" + ((c !== 1) ? "s" : ""); }, - month: function(c) { return (c !== 1) ? "meses" : "mês"; }, - week: function(c) { return "semana" + ((c !== 1) ? "s" : ""); }, - day: function(c) { return "dia" + ((c !== 1) ? "s" : ""); }, - hour: function(c) { return "hora" + ((c !== 1) ? "s" : ""); }, - minute: function(c) { return "minuto" + ((c !== 1) ? "s" : ""); }, - second: function(c) { return "segundo" + ((c !== 1) ? "s" : ""); }, - millisecond: function(c) { return "milissegundo" + ((c !== 1) ? "s" : ""); } + y: function (c) { return 'ano' + (c !== 1 ? 's' : '') }, + mo: function (c) { return c !== 1 ? 'meses' : 'mês' }, + w: function (c) { return 'semana' + (c !== 1 ? 's' : '') }, + d: function (c) { return 'dia' + (c !== 1 ? 's' : '') }, + h: function (c) { return 'hora' + (c !== 1 ? 's' : '') }, + m: function (c) { return 'minuto' + (c !== 1 ? 's' : '') }, + s: function (c) { return 'segundo' + (c !== 1 ? 's' : '') }, + ms: function (c) { return 'milissegundo' + (c !== 1 ? 's' : '') }, + decimal: ',' }, ru: { - year: function(c) { return ["лет", "год", "года"][getRussianForm(c)]; }, - month: function(c) { return ["месяцев", "месяц", "месяца"][getRussianForm(c)]; }, - week: function(c) { return ["недель", "неделя", "недели"][getRussianForm(c)]; }, - day: function(c) { return ["дней", "день", "дня"][getRussianForm(c)]; }, - hour: function(c) { return ["часов", "час", "часа"][getRussianForm(c)]; }, - minute: function(c) { return ["минут", "минута", "минуты"][getRussianForm(c)]; }, - second: function(c) { return ["секунд", "секунда", "секунды"][getRussianForm(c)]; }, - millisecond: function(c) { return ["миллисекунд", "миллисекунда", "миллисекунды"][getRussianForm(c)]; } + y: function (c) { return ['лет', 'год', 'года'][getSlavicForm(c)] }, + mo: function (c) { return ['месяцев', 'месяц', 'месяца'][getSlavicForm(c)] }, + w: function (c) { return ['недель', 'неделя', 'недели'][getSlavicForm(c)] }, + d: function (c) { return ['дней', 'день', 'дня'][getSlavicForm(c)] }, + h: function (c) { return ['часов', 'час', 'часа'][getSlavicForm(c)] }, + m: function (c) { return ['минут', 'минута', 'минуты'][getSlavicForm(c)] }, + s: function (c) { return ['секунд', 'секунда', 'секунды'][getSlavicForm(c)] }, + ms: function (c) { return ['миллисекунд', 'миллисекунда', 'миллисекунды'][getSlavicForm(c)] }, + decimal: ',' + }, + uk: { + y: function (c) { return ['років', 'рік', 'роки'][getSlavicForm(c)] }, + mo: function (c) { return ['місяців', 'місяць', 'місяці'][getSlavicForm(c)] }, + w: function (c) { return ['неділь', 'неділя', 'неділі'][getSlavicForm(c)] }, + d: function (c) { return ['днів', 'день', 'дні'][getSlavicForm(c)] }, + h: function (c) { return ['годин', 'година', 'години'][getSlavicForm(c)] }, + m: function (c) { return ['хвилин', 'хвилина', 'хвилини'][getSlavicForm(c)] }, + s: function (c) { return ['секунд', 'секунда', 'секунди'][getSlavicForm(c)] }, + ms: function (c) { return ['мілісекунд', 'мілісекунда', 'мілісекунди'][getSlavicForm(c)] }, + decimal: ',' }, sv: { - year: "år", - month: function(c) { return "månad" + ((c !== 1) ? "er" : ""); }, - week: function(c) { return "veck" + ((c !== 1) ? "or" : "a"); }, - day: function(c) { return "dag" + ((c !== 1) ? "ar" : ""); }, - hour: function(c) { return "timm" + ((c !== 1) ? "ar" : "e"); }, - minute: function(c) { return "minut" + ((c !== 1) ? "er" : ""); }, - second: function(c) { return "sekund" + ((c !== 1) ? "er" : ""); }, - millisecond: function(c) { return "millisekund" + ((c !== 1) ? "er" : ""); } + y: 'år', + mo: function (c) { return 'månad' + (c !== 1 ? 'er' : '') }, + w: function (c) { return 'veck' + (c !== 1 ? 'or' : 'a') }, + d: function (c) { return 'dag' + (c !== 1 ? 'ar' : '') }, + h: function (c) { return 'timm' + (c !== 1 ? 'ar' : 'e') }, + m: function (c) { return 'minut' + (c !== 1 ? 'er' : '') }, + s: function (c) { return 'sekund' + (c !== 1 ? 'er' : '') }, + ms: function (c) { return 'millisekund' + (c !== 1 ? 'er' : '') }, + decimal: ',' }, tr: { - year: "yıl", - month: "ay", - week: "hafta", - day: "gün", - hour: "saat", - minute: "dakika", - second: "saniye", - millisecond: "milisaniye" + y: 'yıl', + mo: 'ay', + w: 'hafta', + d: 'gün', + h: 'saat', + m: 'dakika', + s: 'saniye', + ms: 'milisaniye', + decimal: ',' + }, + vi: { + y: 'năm', + mo: 'tháng', + w: 'tuần', + d: 'ngày', + h: 'giờ', + m: 'phút', + s: 'giây', + ms: 'mili giây', + decimal: ',' }, - "zh-CN": { - year: "年", - month: "个月", - week: "周", - day: "天", - hour: "小时", - minute: "分钟", - second: "秒", - millisecond: "毫秒" + zh_CN: { + y: '年', + mo: '个月', + w: '周', + d: '天', + h: '小时', + m: '分钟', + s: '秒', + ms: '毫秒', + decimal: '.' }, - "zh-TW": { - year: "年", - month: "個月", - week: "周", - day: "天", - hour: "小時", - minute: "分鐘", - second: "秒", - millisecond: "毫秒" + zh_TW: { + y: '年', + mo: '個月', + w: '周', + d: '天', + h: '小時', + m: '分鐘', + s: '秒', + ms: '毫秒', + decimal: '.' } - }; + } - // You can create a humanizer, which returns a function with defaults + // You can create a humanizer, which returns a function with default // parameters. - function humanizer(passedOptions) { - - var result = function humanizer(ms, humanizerOptions) { - var options = extend({}, result, humanizerOptions || {}); - return doHumanization(ms, options); - }; + function humanizer (passedOptions) { + var result = function humanizer (ms, humanizerOptions) { + var options = extend({}, result, humanizerOptions || {}) + return doHumanization(ms, options) + } return extend(result, { - language: "en", - delimiter: ", ", - spacer: " ", - units: ["year", "month", "week", "day", "hour", "minute", "second"], + language: 'en', + delimiter: ', ', + spacer: ' ', + conjunction: '', + serialComma: true, + units: ['y', 'mo', 'w', 'd', 'h', 'm', 's'], languages: {}, - halfUnit: true, - round: false - }, passedOptions); - + round: false, + unitMeasures: { + y: 31557600000, + mo: 2629800000, + w: 604800000, + d: 86400000, + h: 3600000, + m: 60000, + s: 1000, + ms: 1 + } + }, passedOptions) } // The main function is just a wrapper around a default humanizer. - var defaultHumanizer = humanizer({}); - function humanizeDuration() { - return defaultHumanizer.apply(defaultHumanizer, arguments); - } + var humanizeDuration = humanizer({}) // doHumanization does the bulk of the work. - function doHumanization(ms, options) { + function doHumanization (ms, options) { + var i, len, piece // Make sure we have a positive number. // Has the nice sideffect of turning Number objects into primitives. - ms = Math.abs(ms); + ms = Math.abs(ms) - if (ms === 0) { - return "0"; - } - - var dictionary = options.languages[options.language] || languages[options.language]; + var dictionary = options.languages[options.language] || languages[options.language] if (!dictionary) { - throw new Error("No language " + dictionary + "."); + throw new Error('No language ' + dictionary + '.') } - var result = []; + var pieces = [] // Start at the top and keep removing units, bit by bit. - var unitName, unitMS, unitCount, mightBeHalfUnit; - for (var i = 0, len = options.units.length; i < len; i ++) { + var unitName, unitMS, unitCount + for (i = 0, len = options.units.length; i < len; i++) { + unitName = options.units[i] + unitMS = options.unitMeasures[unitName] - unitName = options.units[i]; - if (unitName[unitName.length - 1] === "s") { // strip plurals - unitName = unitName.substring(0, unitName.length - 1); + // What's the number of full units we can fit? + if (i + 1 === len) { + unitCount = ms / unitMS + } else { + unitCount = Math.floor(ms / unitMS) } - unitMS = UNITS[unitName]; - // If it's a half-unit interval, we're done. - if (result.length === 0 && options.halfUnit) { - mightBeHalfUnit = (ms / unitMS) * 2; - if (mightBeHalfUnit === Math.floor(mightBeHalfUnit)) { - return render(mightBeHalfUnit / 2, unitName, dictionary, options.spacer); - } + // Add the string. + pieces.push({ + unitCount: unitCount, + unitName: unitName + }) + + // Remove what we just figured out. + ms -= unitCount * unitMS + } + + var firstOccupiedUnitIndex = 0 + for (i = 0; i < pieces.length; i++) { + if (pieces[i].unitCount) { + firstOccupiedUnitIndex = i + break } + } - // What's the number of full units we can fit? - if ((i + 1) === len) { - unitCount = ms / unitMS; - if (options.round) { - unitCount = Math.round(unitCount); + if (options.round) { + var ratioToLargerUnit, previousPiece + for (i = pieces.length - 1; i >= 0; i--) { + piece = pieces[i] + piece.unitCount = Math.round(piece.unitCount) + + if (i === 0) { break } + + previousPiece = pieces[i - 1] + + ratioToLargerUnit = options.unitMeasures[previousPiece.unitName] / options.unitMeasures[piece.unitName] + if ((piece.unitCount % ratioToLargerUnit) === 0 || (options.largest && ((options.largest - 1) < (i - firstOccupiedUnitIndex)))) { + previousPiece.unitCount += piece.unitCount / ratioToLargerUnit + piece.unitCount = 0 } - } else { - unitCount = Math.floor(ms / unitMS); } + } - // Add the string. - if (unitCount) { - result.push(render(unitCount, unitName, dictionary, options.spacer)); + var result = [] + for (i = 0, pieces.length; i < len; i++) { + piece = pieces[i] + if (piece.unitCount) { + result.push(render(piece.unitCount, piece.unitName, dictionary, options)) } - // Remove what we just figured out. - ms -= unitCount * unitMS; + if (result.length === options.largest) { break } + } + if (result.length) { + if (!options.conjunction || result.length === 1) { + return result.join(options.delimiter) + } else if (result.length === 2) { + return result.join(options.conjunction) + } else if (result.length > 2) { + return result.slice(0, -1).join(options.delimiter) + (options.serialComma ? ',' : '') + options.conjunction + result.slice(-1) + } + } else { + return render(0, options.units[options.units.length - 1], dictionary, options) } + } - return result.join(options.delimiter); + function render (count, type, dictionary, options) { + var decimal + if (options.decimal === void 0) { + decimal = dictionary.decimal + } else { + decimal = options.decimal + } - } + var countStr = count.toString().replace('.', decimal) - function render(count, type, dictionary, spacer) { - var dictionaryValue = dictionary[type]; - var word; - if (typeof dictionaryValue === "function") { - word = dictionaryValue(count); + var dictionaryValue = dictionary[type] + var word + if (typeof dictionaryValue === 'function') { + word = dictionaryValue(count) } else { - word = dictionaryValue; + word = dictionaryValue } - return count + spacer + word; + + return countStr + options.spacer + word } - function extend(destination) { - var source; - for (var i = 1; i < arguments.length; i ++) { - source = arguments[i]; + function extend (destination) { + var source + for (var i = 1; i < arguments.length; i++) { + source = arguments[i] for (var prop in source) { if (source.hasOwnProperty(prop)) { - destination[prop] = source[prop]; + destination[prop] = source[prop] } } } - return destination; + return destination + } + + // Internal helper function for Czech language. + function getCzechForm (c) { + if (c === 1) { + return 0 + } else if (Math.floor(c) !== c) { + return 1 + } else if (c % 10 >= 2 && c % 10 <= 4 && c % 100 < 10) { + return 2 + } else { + return 3 + } } // Internal helper function for Polish language. - function getPolishForm(c) { + function getPolishForm (c) { if (c === 1) { - return 0; + return 0 } else if (Math.floor(c) !== c) { - return 1; - } else if (2 <= c % 10 && c % 10 <= 4 && !(10 < c % 100 && c % 100 < 20)) { - return 2; + return 1 + } else if (c % 10 >= 2 && c % 10 <= 4 && !(c % 100 > 10 && c % 100 < 20)) { + return 2 } else { - return 3; + return 3 } } - // Internal helper function for Russian language. - function getRussianForm(c) { + // Internal helper function for Russian and Ukranian languages. + function getSlavicForm (c) { if (Math.floor(c) !== c) { - return 2; - } else if (c === 0 || (c >= 5 && c <= 20) || (c % 10 >= 5 && c % 10 <= 9) || (c % 10 === 0)) { - return 0; - } else if (c === 1 || c % 10 === 1) { - return 1; + return 2 + } else if ((c % 100 >= 5 && c % 100 <= 20) || (c % 10 >= 5 && c % 10 <= 9) || c % 10 === 0) { + return 0 + } else if (c % 10 === 1) { + return 1 } else if (c > 1) { - return 2; + return 2 + } else { + return 0 + } + } + + // Internal helper function for Lithuanian language. + function getLithuanianForm (c) { + if (c === 1 || (c % 10 === 1 && c % 100 > 20)) { + return 0 + } else if (Math.floor(c) !== c || (c % 10 >= 2 && c % 100 > 20) || (c % 10 >= 2 && c % 100 < 10)) { + return 1 } else { - return 0; + return 2 } } - function getSupportedLanguages() { - var result = []; + humanizeDuration.getSupportedLanguages = function getSupportedLanguages () { + var result = [] for (var language in languages) { if (languages.hasOwnProperty(language)) { - result.push(language); + result.push(language) } } - return result; + return result } - humanizeDuration.humanizer = humanizer; - humanizeDuration.getSupportedLanguages = getSupportedLanguages; + humanizeDuration.humanizer = humanizer - if (typeof define === "function" && define.amd) { - define(function() { - return humanizeDuration; - }); - } else if (typeof module !== "undefined" && module.exports) { - module.exports = humanizeDuration; + if (typeof define === 'function' && define.amd) { + define(function () { + return humanizeDuration + }) + } else if (typeof module !== 'undefined' && module.exports) { + module.exports = humanizeDuration } else { - this.humanizeDuration = humanizeDuration; + this.humanizeDuration = humanizeDuration } - -})(); +})(); // eslint-disable-line semi diff --git a/dist/assets/js/angular-timer-bower.js b/dist/assets/js/angular-timer-bower.js index 9e89993..dab482b 100644 --- a/dist/assets/js/angular-timer-bower.js +++ b/dist/assets/js/angular-timer-bower.js @@ -262,33 +262,6 @@ e.$validators.maxlength=function(a,c){return 0>f||e.$isEmpty(c)||c.length<=f}}}} * http://www.apache.org/licenses/LICENSE-2.0.txt */ !function(e){"use strict";e(function(){e.support.transition=function(){var e=function(){var e=document.createElement("bootstrap"),t={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},n;for(n in t)if(e.style[n]!==undefined)return t[n]}();return e&&{end:e}}()})}(window.jQuery),!function(e){"use strict";var t='[data-dismiss="alert"]',n=function(n){e(n).on("click",t,this.close)};n.prototype.close=function(t){function s(){i.trigger("closed").remove()}var n=e(this),r=n.attr("data-target"),i;r||(r=n.attr("href"),r=r&&r.replace(/.*(?=#[^\s]*$)/,"")),i=e(r),t&&t.preventDefault(),i.length||(i=n.hasClass("alert")?n:n.parent()),i.trigger(t=e.Event("close"));if(t.isDefaultPrevented())return;i.removeClass("in"),e.support.transition&&i.hasClass("fade")?i.on(e.support.transition.end,s):s()};var r=e.fn.alert;e.fn.alert=function(t){return this.each(function(){var r=e(this),i=r.data("alert");i||r.data("alert",i=new n(this)),typeof t=="string"&&i[t].call(r)})},e.fn.alert.Constructor=n,e.fn.alert.noConflict=function(){return e.fn.alert=r,this},e(document).on("click.alert.data-api",t,n.prototype.close)}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.button.defaults,n)};t.prototype.setState=function(e){var t="disabled",n=this.$element,r=n.data(),i=n.is("input")?"val":"html";e+="Text",r.resetText||n.data("resetText",n[i]()),n[i](r[e]||this.options[e]),setTimeout(function(){e=="loadingText"?n.addClass(t).attr(t,t):n.removeClass(t).removeAttr(t)},0)},t.prototype.toggle=function(){var e=this.$element.closest('[data-toggle="buttons-radio"]');e&&e.find(".active").removeClass("active"),this.$element.toggleClass("active")};var n=e.fn.button;e.fn.button=function(n){return this.each(function(){var r=e(this),i=r.data("button"),s=typeof n=="object"&&n;i||r.data("button",i=new t(this,s)),n=="toggle"?i.toggle():n&&i.setState(n)})},e.fn.button.defaults={loadingText:"loading..."},e.fn.button.Constructor=t,e.fn.button.noConflict=function(){return e.fn.button=n,this},e(document).on("click.button.data-api","[data-toggle^=button]",function(t){var n=e(t.target);n.hasClass("btn")||(n=n.closest(".btn")),n.button("toggle")})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.$indicators=this.$element.find(".carousel-indicators"),this.options=n,this.options.pause=="hover"&&this.$element.on("mouseenter",e.proxy(this.pause,this)).on("mouseleave",e.proxy(this.cycle,this))};t.prototype={cycle:function(t){return t||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(e.proxy(this.next,this),this.options.interval)),this},getActiveIndex:function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},to:function(t){var n=this.getActiveIndex(),r=this;if(t>this.$items.length-1||t<0)return;return this.sliding?this.$element.one("slid",function(){r.to(t)}):n==t?this.pause().cycle():this.slide(t>n?"next":"prev",e(this.$items[t]))},pause:function(t){return t||(this.paused=!0),this.$element.find(".next, .prev").length&&e.support.transition.end&&(this.$element.trigger(e.support.transition.end),this.cycle(!0)),clearInterval(this.interval),this.interval=null,this},next:function(){if(this.sliding)return;return this.slide("next")},prev:function(){if(this.sliding)return;return this.slide("prev")},slide:function(t,n){var r=this.$element.find(".item.active"),i=n||r[t](),s=this.interval,o=t=="next"?"left":"right",u=t=="next"?"first":"last",a=this,f;this.sliding=!0,s&&this.pause(),i=i.length?i:this.$element.find(".item")[u](),f=e.Event("slide",{relatedTarget:i[0],direction:o});if(i.hasClass("active"))return;this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var t=e(a.$indicators.children()[a.getActiveIndex()]);t&&t.addClass("active")}));if(e.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(f);if(f.isDefaultPrevented())return;i.addClass(t),i[0].offsetWidth,r.addClass(o),i.addClass(o),this.$element.one(e.support.transition.end,function(){i.removeClass([t,o].join(" ")).addClass("active"),r.removeClass(["active",o].join(" ")),a.sliding=!1,setTimeout(function(){a.$element.trigger("slid")},0)})}else{this.$element.trigger(f);if(f.isDefaultPrevented())return;r.removeClass("active"),i.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return s&&this.cycle(),this}};var n=e.fn.carousel;e.fn.carousel=function(n){return this.each(function(){var r=e(this),i=r.data("carousel"),s=e.extend({},e.fn.carousel.defaults,typeof n=="object"&&n),o=typeof n=="string"?n:s.slide;i||r.data("carousel",i=new t(this,s)),typeof n=="number"?i.to(n):o?i[o]():s.interval&&i.pause().cycle()})},e.fn.carousel.defaults={interval:5e3,pause:"hover"},e.fn.carousel.Constructor=t,e.fn.carousel.noConflict=function(){return e.fn.carousel=n,this},e(document).on("click.carousel.data-api","[data-slide], [data-slide-to]",function(t){var n=e(this),r,i=e(n.attr("data-target")||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,"")),s=e.extend({},i.data(),n.data()),o;i.carousel(s),(o=n.attr("data-slide-to"))&&i.data("carousel").pause().to(o).cycle(),t.preventDefault()})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.collapse.defaults,n),this.options.parent&&(this.$parent=e(this.options.parent)),this.options.toggle&&this.toggle()};t.prototype={constructor:t,dimension:function(){var e=this.$element.hasClass("width");return e?"width":"height"},show:function(){var t,n,r,i;if(this.transitioning||this.$element.hasClass("in"))return;t=this.dimension(),n=e.camelCase(["scroll",t].join("-")),r=this.$parent&&this.$parent.find("> .accordion-group > .in");if(r&&r.length){i=r.data("collapse");if(i&&i.transitioning)return;r.collapse("hide"),i||r.data("collapse",null)}this.$element[t](0),this.transition("addClass",e.Event("show"),"shown"),e.support.transition&&this.$element[t](this.$element[0][n])},hide:function(){var t;if(this.transitioning||!this.$element.hasClass("in"))return;t=this.dimension(),this.reset(this.$element[t]()),this.transition("removeClass",e.Event("hide"),"hidden"),this.$element[t](0)},reset:function(e){var t=this.dimension();return this.$element.removeClass("collapse")[t](e||"auto")[0].offsetWidth,this.$element[e!==null?"addClass":"removeClass"]("collapse"),this},transition:function(t,n,r){var i=this,s=function(){n.type=="show"&&i.reset(),i.transitioning=0,i.$element.trigger(r)};this.$element.trigger(n);if(n.isDefaultPrevented())return;this.transitioning=1,this.$element[t]("in"),e.support.transition&&this.$element.hasClass("collapse")?this.$element.one(e.support.transition.end,s):s()},toggle:function(){this[this.$element.hasClass("in")?"hide":"show"]()}};var n=e.fn.collapse;e.fn.collapse=function(n){return this.each(function(){var r=e(this),i=r.data("collapse"),s=e.extend({},e.fn.collapse.defaults,r.data(),typeof n=="object"&&n);i||r.data("collapse",i=new t(this,s)),typeof n=="string"&&i[n]()})},e.fn.collapse.defaults={toggle:!0},e.fn.collapse.Constructor=t,e.fn.collapse.noConflict=function(){return e.fn.collapse=n,this},e(document).on("click.collapse.data-api","[data-toggle=collapse]",function(t){var n=e(this),r,i=n.attr("data-target")||t.preventDefault()||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,""),s=e(i).data("collapse")?"toggle":n.data();n[e(i).hasClass("in")?"addClass":"removeClass"]("collapsed"),e(i).collapse(s)})}(window.jQuery),!function(e){"use strict";function r(){e(".dropdown-backdrop").remove(),e(t).each(function(){i(e(this)).removeClass("open")})}function i(t){var n=t.attr("data-target"),r;n||(n=t.attr("href"),n=n&&/#/.test(n)&&n.replace(/.*(?=#[^\s]*$)/,"")),r=n&&e(n);if(!r||!r.length)r=t.parent();return r}var t="[data-toggle=dropdown]",n=function(t){var n=e(t).on("click.dropdown.data-api",this.toggle);e("html").on("click.dropdown.data-api",function(){n.parent().removeClass("open")})};n.prototype={constructor:n,toggle:function(t){var n=e(this),s,o;if(n.is(".disabled, :disabled"))return;return s=i(n),o=s.hasClass("open"),r(),o||("ontouchstart"in document.documentElement&&e('

Countdown Timer

-
+

The countdown timer <timer interval="1000" countdown="100">{{countdown}}</timer> will start its countdown from 100 until it reaches 0 by ticking every second

@@ -233,20 +233,20 @@

{{countdown}}

- +
-
+

Timer with autostart = false

-
+

Click on the start button to start the timer. <timer autostart="false" interval="1000">{{seconds}}</timer>

{{seconds}}

- +
@@ -473,6 +473,15 @@

Same as stop. But, without the event being triggered + + + reset + + + Resets a timer to its initial value, then clears + the timer. + + resume diff --git a/package.json b/package.json index 92e75c3..db7ac43 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { - "author": "Adrian Wardell", + "author": "Siddique Hameed", "name": "angular-timer", "version": "1.3.5", - "homepage": "https://github.com/june07/angular-timer", + "homepage": "https://github.com/siddii/angular-timer", "main": "dist/angular-timer.js", "license": "MIT", "licenses": { "type": "MIT", - "url": "https://github.com/june07/angular-timer/blob/master/LICENSE.txt" + "url": "https://github.com/siddii/angular-timer/blob/master/LICENSE.txt" }, - "bugs": "https://github.com/june07/angular-timer/issues", + "bugs": "https://github.com/siddii/angular-timer/issues", "repository": { "type": "git", - "url": "git@github.com:june07/angular-timer.git" + "url": "git@github.com:siddii/angular-timer.git" }, "dependencies": {}, "devDependencies": { diff --git a/test/e2e/scenarios.js b/test/e2e/scenarios.js index 47d277a..45d15ad 100644 --- a/test/e2e/scenarios.js +++ b/test/e2e/scenarios.js @@ -113,7 +113,7 @@ describe('Angular Timer E2E Tests', function () { expect(element('#auto-start-false-timer timer span').html()).toBeLessThan(100); }); - it('End Time Timer - Ends at beginning of 2014', function () { + it('End Time Timer - Ends at beginning of next year', function () { var beforeTime = element('#timer-with-end-time timer span').html(); sleep(3); var afterTime = element('#timer-with-end-time timer span').html();