Skip to content

Commit

Permalink
padded time output in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
infeeeee committed Jul 18, 2019
1 parent f8fd0ee commit 4058ee0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Integration:
- [ ] Generate output for Rainmeter (Windows) (Just like [kimai-cmd](https://github.com/infeeeee/kimai-cmd))
- [x] Generate output for Argos/Kargos/Bitbar (Gnome, Kde, Mac). More info here: [kimai2-cmd-argos](https://github.com/infeeeee/kimai2-cmd-argos)

Requests for integrations with other softwares are welcomed! Just open an issue and show an example output, what you need.

## Installation

Download executable from [releases](https://github.com/infeeeee/kimai2-cmd/releases/latest). Standalone executable, no installation required.
Expand Down
50 changes: 39 additions & 11 deletions kimai2-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function callKimaiApi(httpMethod, kimaiMethod, serversettings, options = false)
//default options to false:
const qs = options.qs || false
const reqbody = options.reqbody || false

if (program.verbose) {
console.log("calling kimai:", httpMethod, kimaiMethod, serversettings)
}
Expand Down Expand Up @@ -102,6 +102,7 @@ function callKimaiApi(httpMethod, kimaiMethod, serversettings, options = false)
* @param {object} settings The full settings object read from the ini
*/
function uiMainMenu(settings) {
console.log()
inquirer
.prompt([
{
Expand Down Expand Up @@ -406,34 +407,61 @@ function printList(settings, arr, endpoint) {

if (moment(element.end).isValid()) {
//finished measurements:
let dur = moment.duration(moment(element.end).diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
console.log(' Duration: ' + formattedDuration(element.begin, element.end))
} else {
//active measurements:
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
console.log(' Duration: ' + formattedDuration(element.begin))
}

} else if (program.id) {
console.log(element.id + ':', element.project.name, '|', element.activity.name)
} else if (program.argos) {
//Argos
if (endpoint == 'timesheets/recent') {
console.log('--' + element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=restart param2=' + element.id + ' terminal=false refresh=true')
} else if (endpoint == 'timesheets/active') {
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(dur.hours() + ':' + dur.minutes(), element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=stop param2=' + element.id + ' terminal=false refresh=true')
console.log(formattedDuration(element.begin), element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=stop param2=' + element.id + ' terminal=false refresh=true')
}
} else if (program.argosbutton) {
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(dur.hours() + ':' + dur.minutes(), element.project.name + ',', element.activity.name, '| length=' + settings.argos_bitbar.buttonlength)
//Argosbutton
console.log(formattedDuration(element.begin), element.project.name + ',', element.activity.name, '| length=' + settings.argos_bitbar.buttonlength)
} else {
console.log(element.project.name, '|', element.activity.name)
console.log()
//Regular output
if (moment(element.end).isValid()) {
//finished measurements:
console.log(element.project.name, '|', element.activity.name)
} else {
//active measurements:
console.log(formattedDuration(element.begin), element.project.name, '|', element.activity.name)
}
}
}
}
}

/**
* Returns duration between the two moments or between beginning and now. padded to minimum two digits.
*
* @param {moment} begin beginning moment
* @param {moment} end optional, end moment
*/
function formattedDuration(begin, end) {
let momentDuration = moment.duration(moment(end).diff(moment(begin)))

let hrs = momentDuration.hours()
let mins = momentDuration.minutes()

if (hrs.toString().length == 1) {
hrs = "0" + hrs
}

if (mins.toString().length == 1) {
mins = "0" + mins
}

return hrs + ':' + mins
}


/**
* Interactive ui: select measurement from a list of measurements
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kimai2-cmd",
"version": "0.2.2",
"version": "0.2.3",
"description": "Command line client for Kimai2",
"main": "kimai2-cmd.js",
"bin": "kimai2-cmd.js",
Expand Down

0 comments on commit 4058ee0

Please sign in to comment.