mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
- Updated `date_utils.rb` to return `nil` for timestamps equal to 0. - Enhanced `SimplefinItem::Importer` to merge transactions by prioritizing non-pending records with valid posted timestamps. - Introduced a comparator and key-builder for resolving transaction conflicts systematically. Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
30 lines
632 B
Ruby
30 lines
632 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Simplefin
|
|
module DateUtils
|
|
module_function
|
|
|
|
# Parses provider-supplied dates that may be String (ISO), Numeric (epoch seconds),
|
|
# Time/DateTime, or Date. Returns a Date or nil when unparseable.
|
|
def parse_provider_date(val)
|
|
return nil if val.nil?
|
|
|
|
case val
|
|
when Date
|
|
val
|
|
when Time, DateTime
|
|
val.to_date
|
|
when Integer, Float
|
|
return nil if val.to_i == 0
|
|
Time.at(val).utc.to_date
|
|
when String
|
|
Date.parse(val)
|
|
else
|
|
nil
|
|
end
|
|
rescue ArgumentError, TypeError
|
|
nil
|
|
end
|
|
end
|
|
end
|