added gitignore file and updated some stuff
This commit is contained in:
parent
4998e24dfc
commit
2437680c29
4 changed files with 47 additions and 10 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
__debug_bin
|
||||
worklog
|
|
@ -58,9 +58,27 @@ func StopTimestamp() (bool, Timestamp) {
|
|||
}
|
||||
|
||||
func GetFirstTimestamp(user string, date time.Time) Timestamp {
|
||||
return GetTodaysTimestamp(user, date, true)
|
||||
}
|
||||
|
||||
func GetLastTimestamp(user string, date time.Time) Timestamp {
|
||||
return GetTodaysTimestamp(user, date, false)
|
||||
}
|
||||
|
||||
func GetTodaysTimestamp(user string, date time.Time, first bool) Timestamp {
|
||||
var timestamp Timestamp
|
||||
date = time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, time.UTC)
|
||||
connection.Where("start > ? and user = ?", date, user).First(×tamp)
|
||||
var where string
|
||||
var order string
|
||||
if first {
|
||||
date = time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, time.UTC)
|
||||
order = "asc"
|
||||
where = "start > ?"
|
||||
} else {
|
||||
date = time.Date(date.Year(), date.Month(), date.Day(), 23, 59, 59, 0, time.UTC)
|
||||
order = "desc"
|
||||
where = "start < ?"
|
||||
}
|
||||
connection.Where(where+" and user = ?", date, user).Order("start " + order).First(×tamp)
|
||||
return timestamp
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ func TimeToDDMMYYYY(time time.Time) string {
|
|||
}
|
||||
|
||||
func TimeToHHMMSS(time time.Time) string {
|
||||
if time == ZeroDate {
|
||||
return ""
|
||||
}
|
||||
tmp := strconv.Itoa(time.Second())
|
||||
if len(tmp) < 2 {
|
||||
tmp = "0" + tmp
|
||||
|
|
|
@ -41,6 +41,7 @@ func ToJSON(from time.Time, to time.Time, user string) (string, error) {
|
|||
Stop: tools.TimeToHHMMSS(workday.Stop),
|
||||
Duration: tools.DurationToHHMMSS(workday.Duration),
|
||||
}
|
||||
workdayJson.Open = workday.isOpen()
|
||||
if workday.Pause.Duration > 0 {
|
||||
pauseJson := pauseJson{
|
||||
Start: tools.TimeToHHMMSS(workday.Pause.Start),
|
||||
|
@ -63,6 +64,7 @@ func (workday *Workday) ToJSON(user string) (string, error) {
|
|||
Stop: tools.TimeToHHMMSS(workday.Stop),
|
||||
Duration: tools.DurationToHHMMSS(workday.Duration),
|
||||
}
|
||||
workdayJson.Open = workday.isOpen()
|
||||
if workday.Pause.Duration > 0 {
|
||||
pauseJson := pauseJson{
|
||||
Start: tools.TimeToHHMMSS(workday.Pause.Start),
|
||||
|
@ -77,17 +79,24 @@ func (workday *Workday) ToJSON(user string) (string, error) {
|
|||
|
||||
func GetToday(user string) (Workday, error) {
|
||||
var workday Workday
|
||||
timestamp := database.GetFirstTimestamp(user, time.Now())
|
||||
if timestamp.ID == 0 {
|
||||
firstTimestamp := database.GetFirstTimestamp(user, time.Now())
|
||||
if firstTimestamp.ID == 0 {
|
||||
return workday, errors.New("no workday for user '" + user + "' started today")
|
||||
}
|
||||
workday.Date = tools.TimeToDDMMYYYY(timestamp.Start)
|
||||
workday.Start = timestamp.Start
|
||||
workday.Stop = timestamp.End
|
||||
if workday.Stop == tools.ZeroDate {
|
||||
workday.Stop = time.Now()
|
||||
}
|
||||
workday.Date = tools.TimeToDDMMYYYY(firstTimestamp.Start)
|
||||
workday.Start = firstTimestamp.Start
|
||||
workday.Stop = firstTimestamp.End
|
||||
workday.Duration = workday.Stop.Sub(workday.Start)
|
||||
if workday.isOpen() {
|
||||
return workday, nil
|
||||
}
|
||||
currentTimestamp := database.GetLastTimestamp(user, time.Now())
|
||||
workday.Stop = currentTimestamp.End
|
||||
if workday.Stop == tools.ZeroDate {
|
||||
workday.Duration = time.Since(workday.Start)
|
||||
} else {
|
||||
workday.Duration = workday.Stop.Sub(workday.Start)
|
||||
}
|
||||
return workday, nil
|
||||
}
|
||||
|
||||
|
@ -144,6 +153,10 @@ func aggregatedTimestampsToWorkdays(aggregatedTimestamps map[string][]database.T
|
|||
return workdays
|
||||
}
|
||||
|
||||
func (workday *Workday) isOpen() bool {
|
||||
return workday.Stop == tools.ZeroDate
|
||||
}
|
||||
|
||||
func (workday *Workday) insertFakePause() {
|
||||
var pause Pause
|
||||
deviationStart := rand.Intn(15-(-15)) + (-15)
|
||||
|
@ -177,6 +190,7 @@ type workdayJson struct {
|
|||
Start string
|
||||
Stop string
|
||||
Duration string
|
||||
Open bool
|
||||
Pause pauseJson
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue