【发布时间】:2016-01-02 06:24:50
【问题描述】:
我正在尝试设置一种方法来创建比较这些列的每日计划:
我正在存储 paypal IPN next_payment_date,它的格式与默认的 rails 格式不同
示例
贝宝 ipn
"next_payment_date"=>"03:00:00 Oct 06, 2015 PDT"
导轨
created_at: "2015-10-05 14:24:17"
这些是不同的格式,我不太确定 rails 是否可以比较它们。
例如
我尝试像这样将next_payment_date 存储为datetime
subscription = Subscription.find_by(paypal_recurring_profile_token: params[:recurring_payment_id])
if params[:next_payment_date]
subscription.update_attributes(paid_until: params[:next_payment_date])
end
这是贝宝日期:
"next_payment_date"=>"03:00:00 Oct 06, 2015 PDT"
这就是 rails 存储的内容
paid_until: "2015-10-05 03:00:06"
似乎 rails 确实知道一点,但它不会转换月份和日期,只是时间。
存储这些参数的正确方法是什么?
编辑
架构:
create_table "payment_notifications", force: :cascade do |t|
t.text "params"
t.integer "user_role_id"
t.string "status"
t.string "transaction_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "txn_type"
t.string "recurring_payment_profile_id"
end
create_table "subscriptions", force: :cascade do |t|
t.integer "user_role_id"
t.integer "user_id"
t.string "paypal_customer_token"
t.string "paypal_recurring_profile_token"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "paid_until"
t.boolean "canceled", default: false
end
编辑 2
试图转换字符串时间但似乎乱序:
irb(main):006:0> PaymentNotification.last.params[:next_payment_date]
PaymentNotification Load (1.9ms) SELECT "payment_notifications".* FROM "payment_notifications" ORDER BY "payment_notifications"."id" DESC LIMIT 1
=> "03:00:00 Oct 07, 2015 PDT"
irb(main):007:0> PaymentNotification.last.params[:next_payment_date].to_time
PaymentNotification Load (4.7ms) SELECT "payment_notifications".* FROM "payment_notifications" ORDER BY "payment_notifications"."id" DESC LIMIT 1
=> 2015-10-06 03:00:07 +0000
【问题讨论】:
标签: ruby-on-rails datetime paypal paypal-ipn