-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
472 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- insert issue number if this PR fixes one or multiple issues --> | ||
|
||
- Fixes # | ||
|
||
# Purpose | ||
|
||
<!-- describe the purpose of the pull request. Include background information if necessary. --> | ||
|
||
# Description of Change | ||
|
||
<!-- Add a more detailed description on how and why this PR solves the issue or why the new feature should be added --> | ||
|
||
# Todos | ||
|
||
<!-- add a list of open things to clear up before the PR should be merged --> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const BUDGET_TYPE = { | ||
MINUTES_PER_MONTH: 'minutes_per_month', | ||
MINUTES: 'minutes', | ||
CENTS: 'cents', | ||
CENTS_PER_MONTH: 'cents_per_month', | ||
}; | ||
|
||
const DEFAULT_CURRENCY = '€'; | ||
|
||
module.exports = { | ||
BUDGET_TYPE: BUDGET_TYPE, | ||
|
||
minutesToWorkDays(minutes) { | ||
return this.number(minutes / 8 / 60, 2); | ||
}, | ||
|
||
minutesToDuration(minutes) { | ||
if (typeof minutes !== 'number') { | ||
throw new TypeError('Expected minutes to be a of type Number'); | ||
} else if (isNaN(minutes)) { | ||
throw new Error('Expected minutes to be a valid Number not NaN'); | ||
} else if (!isFinite(minutes)) { | ||
throw new Error('Expecte minutes not to be a finite value.'); | ||
} | ||
let hours = Math.floor(minutes / 60) | ||
let remainingMinutes = Math.round(minutes - hours * 60); | ||
if (String(remainingMinutes).length === 1) { | ||
return hours + ':0' + remainingMinutes | ||
} | ||
return hours + ':' + remainingMinutes; | ||
}, | ||
|
||
number(value, precision) { | ||
if (typeof value !== 'number') { | ||
throw new TypeError('Expected value to be a of type Number'); | ||
} else if (isNaN(value)) { | ||
throw new Error('Expected value to be a valid Number not NaN'); | ||
} else if (!isFinite(value)) { | ||
throw new Error('Expecte value not to be a finite value.'); | ||
} | ||
precision = precision || 2; | ||
return String(value.toFixed(precision)); | ||
}, | ||
|
||
price(value, precision) { | ||
precision = precision || 2; | ||
return String(value.toFixed(precision)); | ||
}, | ||
|
||
budget(type, value) { | ||
switch(type) { | ||
case BUDGET_TYPE.MINUTES_PER_MONTH: | ||
return this.minutesToDuration(value) + ' h/m'; | ||
case BUDGET_TYPE.MINUTES: | ||
return this.minutesToDuration(value) + ' h'; | ||
case BUDGET_TYPE.CENTS: | ||
return this.price(value / 100) + ' ' + DEFAULT_CURRENCY; | ||
case BUDGET_TYPE.CENTS_PER_MONTH: | ||
return this.price(value / 100) + ' ' + DEFAULT_CURRENCY + '/m'; | ||
default: | ||
throw new Error('Unknown budget format type: "' + type + '"'); | ||
} | ||
} | ||
} |
Oops, something went wrong.