Skip to content

Commit 3a9a8f2

Browse files
committed
Simplify fieldValuesFromTime() implementation
1 parent 8a7d6d7 commit 3a9a8f2

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

arrow/extensions/timestamp_with_offset.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,10 @@ func timeFromFieldValues(utcTimestamp arrow.Timestamp, offsetMinutes int16, unit
239239
}
240240

241241
func fieldValuesFromTime(t time.Time, unit arrow.TimeUnit) (arrow.Timestamp, int16) {
242-
// naive "bitwise" conversion to UTC, keeping the underlying date the same
243-
utc := t.UTC()
244-
naiveUtc := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.UTC)
245-
offsetMinutes := int16(naiveUtc.Sub(t).Minutes())
246-
247-
// SAFETY: unit MUST have been validated to a valid arrow.TimeUnit value before
248-
// this function. Otherwise, ignoring this error is not safe.
249-
timestamp, _ := arrow.TimestampFromTime(utc, unit)
250-
return timestamp, offsetMinutes
242+
_, offsetSeconds := t.Zone()
243+
offsetMinutes := int16(offsetSeconds / 60)
244+
ts, _ := arrow.TimestampFromTime(t.UTC(), unit)
245+
return ts, offsetMinutes
251246
}
252247

253248
// Get the raw arrow values at the given index

0 commit comments

Comments
 (0)