Skip to content

Commit 981281b

Browse files
committed
add biweekly period
1 parent 54f9a66 commit 981281b

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

cmd/lweb/handler_report.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@ import (
1010

1111
"github.com/go-martini/martini"
1212
"github.com/howeyc/ledger"
13-
"github.com/lucasb-eyer/go-colorful"
13+
colorful "github.com/lucasb-eyer/go-colorful"
1414
)
1515

1616
func getRangeAndPeriod(dateRange, dateFreq string) (start, end time.Time, period ledger.Period) {
17-
switch dateFreq {
18-
case "Weekly":
19-
period = ledger.PeriodWeek
20-
case "Monthly":
21-
period = ledger.PeriodMonth
22-
case "Quarterly":
23-
period = ledger.PeriodQuarter
24-
case "Yearly":
25-
period = ledger.PeriodYear
26-
case "SemiYearly":
27-
period = ledger.PeriodSemiYear
28-
default:
29-
period = ledger.PeriodMonth
30-
}
17+
period = ledger.Period(dateFreq)
3118

3219
currentTime := time.Now()
3320
switch dateRange {

date.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Period string
2525
// Periods suppored by ledger
2626
const (
2727
PeriodWeek Period = "Weekly"
28+
Period2Week Period = "BiWeekly"
2829
PeriodMonth Period = "Monthly"
2930
PeriodQuarter Period = "Quarterly"
3031
PeriodYear Period = "Yearly"
@@ -41,6 +42,11 @@ func getDateBoundaries(per Period, start, end time.Time) []time.Time {
4142
for periodStart = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.UTC); periodStart.Weekday() != time.Sunday; {
4243
periodStart = periodStart.AddDate(0, 0, -1)
4344
}
45+
case Period2Week:
46+
incDays = 14
47+
for periodStart = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.UTC); periodStart.Weekday() != time.Sunday; {
48+
periodStart = periodStart.AddDate(0, 0, -1)
49+
}
4450
case PeriodMonth:
4551
incMonth = 1
4652
periodStart = time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, time.UTC)

0 commit comments

Comments
 (0)