package gotime import "time" 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 = tmr t1.before.End = *new(time.Time) t2 := CreateIntervalTxn() t2.after = tmr return []Transaction{*t1, *t2} } 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"]} */