mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
transaction month list supports browser time zone
This commit is contained in:
@@ -243,7 +243,7 @@ func (a *TransactionsApi) TransactionMonthListHandler(c *core.Context) (interfac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transactions, err := a.transactions.GetTransactionsInMonthByPage(uid, transactionListReq.Year, transactionListReq.Month, transactionListReq.Type, allCategoryIds, transactionListReq.AccountId, transactionListReq.Keyword, transactionListReq.Page, transactionListReq.Count)
|
transactions, err := a.transactions.GetTransactionsInMonthByPage(uid, transactionListReq.Year, transactionListReq.Month, transactionListReq.Type, allCategoryIds, transactionListReq.AccountId, transactionListReq.Keyword, transactionListReq.Page, transactionListReq.Count, utcOffset)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorfWithRequestId(c, "[transactions.TransactionMonthListHandler] failed to get transactions in month \"%d-%d\" for user \"uid:%d\", because %s", transactionListReq.Year, transactionListReq.Month, uid, err.Error())
|
log.ErrorfWithRequestId(c, "[transactions.TransactionMonthListHandler] failed to get transactions in month \"%d-%d\" for user \"uid:%d\", because %s", transactionListReq.Year, transactionListReq.Month, uid, err.Error())
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func (s *TransactionService) GetTransactionsByMaxTime(uid int64, maxTime int64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactionsInMonthByPage returns transactions in given year and month
|
// GetTransactionsInMonthByPage returns transactions in given year and month
|
||||||
func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, month int, transactionType models.TransactionDbType, categoryIds []int64, accountId int64, keyword string, page int, count int) ([]*models.Transaction, error) {
|
func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, month int, transactionType models.TransactionDbType, categoryIds []int64, accountId int64, keyword string, page int, count int, utcOffset int16) ([]*models.Transaction, error) {
|
||||||
if uid <= 0 {
|
if uid <= 0 {
|
||||||
return nil, errs.ErrUserIdInvalid
|
return nil, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, m
|
|||||||
return nil, errs.ErrPageCountInvalid
|
return nil, errs.ErrPageCountInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime, err := utils.ParseFromLongDateTime(fmt.Sprintf("%d-%d-01 00:00:00", year, month))
|
startTime, err := utils.ParseFromLongDateTime(fmt.Sprintf("%d-%d-01 00:00:00", year, month), utcOffset)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.ErrSystemError
|
return nil, errs.ErrSystemError
|
||||||
@@ -260,12 +260,12 @@ func (s *TransactionService) GetAllTransactionCount(uid int64) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMonthTransactionCount returns total count of transactions in given year and month
|
// GetMonthTransactionCount returns total count of transactions in given year and month
|
||||||
func (s *TransactionService) GetMonthTransactionCount(uid int64, year int64, month int64) (int64, error) {
|
func (s *TransactionService) GetMonthTransactionCount(uid int64, year int64, month int64, utcOffset int16) (int64, error) {
|
||||||
if uid <= 0 {
|
if uid <= 0 {
|
||||||
return 0, errs.ErrUserIdInvalid
|
return 0, errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime, err := utils.ParseFromLongDateTime(fmt.Sprintf("%d-%d-01 00:00:00", year, month))
|
startTime, err := utils.ParseFromLongDateTime(fmt.Sprintf("%d-%d-01 00:00:00", year, month), utcOffset)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errs.ErrSystemError
|
return 0, errs.ErrSystemError
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ func ParseFromUnixTime(unixTime int64) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseFromLongDateTime parses a formatted string in long date time format
|
// ParseFromLongDateTime parses a formatted string in long date time format
|
||||||
func ParseFromLongDateTime(t string) (time.Time, error) {
|
func ParseFromLongDateTime(t string, utcOffset int16) (time.Time, error) {
|
||||||
return time.Parse(longDateTimeFormat, t)
|
timezone := time.FixedZone("Timezone", int(utcOffset)*60)
|
||||||
|
return time.ParseInLocation(longDateTimeFormat, t, timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMinTransactionTimeFromUnixTime returns the minimum transaction time from unix time
|
// GetMinTransactionTimeFromUnixTime returns the minimum transaction time from unix time
|
||||||
|
|||||||
Reference in New Issue
Block a user