You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
1.9 KiB
100 lines
1.9 KiB
package gotime
|
|
|
|
type Transaction struct {
|
|
tp string
|
|
before *Timer
|
|
after *Timer
|
|
}
|
|
|
|
func CreateStartTimerTxns(tmr *Timer) []Transaction {
|
|
t := CreateIntervalTxn()
|
|
t.after = tmr
|
|
return []Transaction{*t}
|
|
}
|
|
|
|
func CreateStopTimerTxns(tmr *Timer) []Transaction {
|
|
t1 := CreateIntervalTxn()
|
|
t1.before = new(Timer)
|
|
t1.before.Beg = tmr.Beg
|
|
t1.before.Tags = tmr.Tags
|
|
|
|
t2 := CreateIntervalTxn()
|
|
t2.after = tmr
|
|
|
|
return []Transaction{*t1, *t2}
|
|
}
|
|
|
|
func CreateTagChangeTxns(tmr *Timer, oldTags []string) []Transaction {
|
|
t := CreateIntervalTxn()
|
|
t.before = new(Timer)
|
|
t.before.Beg = tmr.Beg
|
|
t.before.End = tmr.End
|
|
t.before.Tags = oldTags
|
|
t.after = tmr
|
|
|
|
return []Transaction{*t}
|
|
}
|
|
|
|
func CreateTxn(oldTmr, newTmr *Timer) *Transaction {
|
|
t := Transaction{
|
|
tp: "interval",
|
|
before: oldTmr,
|
|
after: newTmr,
|
|
}
|
|
return &t
|
|
}
|
|
|
|
func CreateIntervalTxn() *Transaction {
|
|
t := new(Transaction)
|
|
t.tp = "interval"
|
|
t.before = new(Timer)
|
|
t.after = new(Timer)
|
|
return t
|
|
}
|
|
|
|
func (t *Transaction) SetBefore(tmr *Timer) {
|
|
t.before = tmr
|
|
}
|
|
|
|
func (t *Transaction) SetAfter(tmr *Timer) {
|
|
t.after = tmr
|
|
}
|
|
|
|
func (t *Transaction) ToString() string {
|
|
ret := "txn:\n"
|
|
ret += " type: " + t.tp + "\n"
|
|
ret += " before: " + t.before.ToJsonString() + "\n"
|
|
ret += " after: " + t.after.ToJsonString() + "\n"
|
|
return ret
|
|
}
|
|
|
|
/*
|
|
* START Transaction
|
|
|
|
txn:
|
|
type: interval
|
|
before:
|
|
after: {"start":"20170111T223025Z","tags":["bcw","bcw-gotime","work"]}
|
|
|
|
*
|
|
*
|
|
* STOP Transaction
|
|
|
|
txn:
|
|
type: interval
|
|
before: {"start":"20170111T201826Z","tags":["bcw","bcw-gotime","work"]}
|
|
after:
|
|
txn:
|
|
type: interval
|
|
before:
|
|
after: {"start":"20170111T201826Z","end":"20170111T221747Z","tags":["bcw","bcw-gotime","work"]}
|
|
|
|
*
|
|
*
|
|
* TAG Transaction
|
|
|
|
txn:
|
|
type: interval
|
|
before: {"start":"20170112T123633Z","tags":["bcw","bcw-gotime","work"]}
|
|
after: {"start":"20170112T123633Z","tags":["bcw","bcw-gotime","test","work"]}
|
|
*/
|
|
|