Files
openfoodnetwork/engines/dfc_provider/app/services/sale_session_builder.rb
Maikel Linke 6c6927af84 Add SaleSession with correct OrderCycle times
Apparently, the FDC implementation uses those dates to finalise orders.
2024-09-25 10:55:39 +10:00

19 lines
575 B
Ruby

# frozen_string_literal: true
class SaleSessionBuilder < DfcBuilder
def self.build(order_cycle)
DataFoodConsortium::Connector::SaleSession.new(
nil,
beginDate: stringify_time(order_cycle&.orders_open_at),
endDate: stringify_time(order_cycle&.orders_close_at),
)
end
# This should be a standard JSON format but for now we format it the same
# way as the FDC because that's the only way they can parse it.
# Example: Thu Aug 22 2024 05:40:38 UTC
def self.stringify_time(time)
time&.utc&.strftime("%a %b %d %Y %H:%M:%S %Z")
end
end