code refactor
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package converters
|
||||
|
||||
import "time"
|
||||
|
||||
// ImportedDataTable defines the structure of imported data table
|
||||
type ImportedDataTable interface {
|
||||
// DataRowCount returns the total count of data row
|
||||
@@ -19,6 +21,12 @@ type ImportedDataRow interface {
|
||||
|
||||
// GetData returns the data in the specified column index
|
||||
GetData(columnIndex int) string
|
||||
|
||||
// GetTime returns the time in the specified column index
|
||||
GetTime(columnIndex int, timezoneOffset int16) (time.Time, error)
|
||||
|
||||
// GetTimezoneOffset returns the time zone offset in the specified column index
|
||||
GetTimezoneOffset(columnIndex int) (*time.Location, error)
|
||||
}
|
||||
|
||||
// ImportedDataRowIterator defines the structure of imported data row iterator
|
||||
|
||||
@@ -252,7 +252,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
|
||||
timezoneOffset := defaultTimezoneOffset
|
||||
|
||||
if timezoneColumnExists {
|
||||
transactionTimezone, err := utils.ParseFromTimezoneOffset(dataRow.GetData(timezoneColumnIdx))
|
||||
transactionTimezone, err := dataRow.GetTimezoneOffset(timezoneColumnIdx)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse time zone \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(timezoneColumnIdx), dataRowIndex, user.Uid, err.Error())
|
||||
@@ -262,7 +262,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
|
||||
timezoneOffset = utils.GetTimezoneOffsetMinutes(transactionTimezone)
|
||||
}
|
||||
|
||||
transactionTime, err := utils.ParseFromLongDateTime(dataRow.GetData(timeColumnIdx), timezoneOffset)
|
||||
transactionTime, err := dataRow.GetTime(timeColumnIdx, timezoneOffset)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse time \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(timeColumnIdx), dataRowIndex, user.Uid, err.Error())
|
||||
|
||||
@@ -3,8 +3,10 @@ package converters
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||
)
|
||||
|
||||
// ezBookKeepingTransactionPlainTextDataTable defines the structure of ezbookkeeping transaction plain text data table
|
||||
@@ -68,6 +70,16 @@ func (r *ezBookKeepingTransactionPlainTextDataRow) GetData(columnIndex int) stri
|
||||
return r.allItems[columnIndex]
|
||||
}
|
||||
|
||||
// GetTime returns the time in the specified column index
|
||||
func (r *ezBookKeepingTransactionPlainTextDataRow) GetTime(columnIndex int, timezoneOffset int16) (time.Time, error) {
|
||||
return utils.ParseFromLongDateTime(r.GetData(columnIndex), timezoneOffset)
|
||||
}
|
||||
|
||||
// GetTimezoneOffset returns the time zone offset in the specified column index
|
||||
func (r *ezBookKeepingTransactionPlainTextDataRow) GetTimezoneOffset(columnIndex int) (*time.Location, error) {
|
||||
return utils.ParseFromTimezoneOffset(r.GetData(columnIndex))
|
||||
}
|
||||
|
||||
// HasNext returns whether the iterator does not reach the end
|
||||
func (t *ezBookKeepingTransactionPlainTextDataRowIterator) HasNext() bool {
|
||||
return t.currentIndex+1 < len(t.dataTable.allLines)
|
||||
|
||||
Reference in New Issue
Block a user