add api for getting total income/expense amounts by month
This commit is contained in:
@@ -5,6 +5,8 @@ import "time"
|
||||
const (
|
||||
longDateTimeFormat = "2006-01-02 15:04:05"
|
||||
longDateTimeWithoutSecondFormat = "2006-01-02 15:04"
|
||||
shortDateTimeFormat = "2006-1-2 15:4:5"
|
||||
yearMonthDateTimeFormat = "2006-01"
|
||||
)
|
||||
|
||||
// FormatUnixTimeToLongDateTimeInServerTimezone returns a textual representation of the unix time formatted by long date time format
|
||||
@@ -23,6 +25,17 @@ func FormatUnixTimeToLongDateTimeWithoutSecond(unixTime int64, timezone *time.Lo
|
||||
return t.Format(longDateTimeWithoutSecondFormat)
|
||||
}
|
||||
|
||||
// FormatUnixTimeToYearMonth returns year and month of specified unix time
|
||||
func FormatUnixTimeToYearMonth(unixTime int64, timezone *time.Location) string {
|
||||
t := ParseFromUnixTime(unixTime)
|
||||
|
||||
if timezone != nil {
|
||||
t = t.In(timezone)
|
||||
}
|
||||
|
||||
return t.Format(yearMonthDateTimeFormat)
|
||||
}
|
||||
|
||||
// ParseFromUnixTime parses a unix time and returns a golang time struct
|
||||
func ParseFromUnixTime(unixTime int64) time.Time {
|
||||
return time.Unix(unixTime, 0)
|
||||
@@ -34,6 +47,12 @@ func ParseFromLongDateTime(t string, utcOffset int16) (time.Time, error) {
|
||||
return time.ParseInLocation(longDateTimeFormat, t, timezone)
|
||||
}
|
||||
|
||||
// ParseFromShortDateTime parses a formatted string in short date time format
|
||||
func ParseFromShortDateTime(t string, utcOffset int16) (time.Time, error) {
|
||||
timezone := time.FixedZone("Timezone", int(utcOffset)*60)
|
||||
return time.ParseInLocation(shortDateTimeFormat, t, timezone)
|
||||
}
|
||||
|
||||
// GetMinTransactionTimeFromUnixTime returns the minimum transaction time from unix time
|
||||
func GetMinTransactionTimeFromUnixTime(unixTime int64) int64 {
|
||||
return unixTime * 1000
|
||||
|
||||
Reference in New Issue
Block a user