parent
52345cc98f
commit
5bbfaf7696
@ -0,0 +1,36 @@ |
||||
package cyclops_utils |
||||
|
||||
import ( |
||||
"time" |
||||
) |
||||
|
||||
func GetReportingPeriod(inputdate string) (err error, from, to string) { |
||||
err = nil |
||||
layout := "2006-01-02" |
||||
t, err := time.Parse(layout, inputdate) |
||||
if err != nil { |
||||
return |
||||
} |
||||
y, m, d := t.Date() |
||||
|
||||
valTo := t.AddDate(0, 0, -1) |
||||
to = valTo.Format("2006-01-02") |
||||
valFrom := time.Now() |
||||
if d == 1 && (m == 1 || m == 4 || m == 7 || m == 10) { |
||||
//subtracting 1 day
|
||||
valFrom = t.AddDate(0,-3,0) |
||||
|
||||
} else { |
||||
if m >= 1 && m <= 3 { |
||||
valFrom = time.Date(y, time.January, 1,0,0,0,0, time.UTC) |
||||
} else if m >= 4 && m <= 6 { |
||||
valFrom = time.Date(y, time.April, 1,0,0,0,0, time.UTC) |
||||
} else if m >= 7 && m <= 9 { |
||||
valFrom = time.Date(y, time.July, 1,0,0,0,0, time.UTC) |
||||
} else if m >= 10 && m <= 12 { |
||||
valFrom = time.Date(y, time.October, 1,0,0,0,0, time.UTC) |
||||
} |
||||
} |
||||
from = valFrom.Format("2006-01-02") |
||||
return |
||||
} |
@ -0,0 +1,16 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"gitlab.com/cyclops-utilities/date-utils/cyclops_utils" |
||||
|
||||
) |
||||
|
||||
func main() { |
||||
err, from, to := cyclops_utils.GetReportingPeriod("2019-10-01") |
||||
if err != nil { |
||||
fmt.Errorf("Error in processing input: %s", err.Error()) |
||||
} else { |
||||
fmt.Printf("From: %s, To: %s\n", from, to); |
||||
} |
||||
} |
Loading…
Reference in new issue