rudimentary date parsing
parent
82de5ef468
commit
7a337c43a4
22
index.js
22
index.js
|
@ -10,17 +10,29 @@ function sleep(n) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dateToInterval(d="today") {
|
||||||
|
const now = DateTime.local()
|
||||||
|
let retDate
|
||||||
|
if (d == "today") {
|
||||||
|
retDate = now.startOf('day')
|
||||||
|
} else if (d == "yesterday") {
|
||||||
|
retDate = now.startOf('day').minus({days: 1})
|
||||||
|
} else {
|
||||||
|
retDate = DateTime.fromISO(d)
|
||||||
|
}
|
||||||
|
return Interval.fromDateTimes(retDate.startOf('day'), retDate.endOf('day'))
|
||||||
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
(async function() {
|
(async function() {
|
||||||
const m = new Marvin()
|
const m = new Marvin()
|
||||||
const d = DateTime.local()
|
const interval = dateToInterval(process.argv.length > 2 ? process.argv[2] : 'today')
|
||||||
const today = Interval.fromDateTimes(d.startOf('day'), d.endOf('day'))
|
const tasks = await (m.root.category('Tweag').then(tweag => tweag.tasksOverlapping(interval)))
|
||||||
const tasks = await (m.root.category('Tweag').then(tweag => tweag.tasksOverlapping(today)))
|
const value = Duration.sum(tasks.map(task => task.timeSpentOn(interval))).as('hours')
|
||||||
const value = Duration.sum(tasks.map(task => task.timeSpentOn(today))).as('hours')
|
|
||||||
|
|
||||||
const b = new Beeminder(BEEMINDER_TOKEN)
|
const b = new Beeminder(BEEMINDER_TOKEN)
|
||||||
const goal = b.user("me").goal("loonslaven")
|
const goal = b.user("me").goal("loonslaven")
|
||||||
const daystamp = d.toFormat('yyyyMMdd')
|
const daystamp = interval.start.toFormat('yyyyMMdd')
|
||||||
const post_data = {
|
const post_data = {
|
||||||
daystamp,
|
daystamp,
|
||||||
value,
|
value,
|
||||||
|
|
Loading…
Reference in New Issue