Browse Source

Parse dates with Date.parse for format detection

Maarten van den Berg 6 years ago
parent
commit
fe0f4511db
1 changed files with 4 additions and 4 deletions
  1. 4 4
      app/models/activity.rb

+ 4 - 4
app/models/activity.rb

174
       a.description = row['description']
174
       a.description = row['description']
175
       a.location    = row['location']
175
       a.location    = row['location']
176
 
176
 
177
-      sd            = Date.strptime(row['start_date'])
177
+      sd            = Date.parse row['start_date']
178
       st            = Time.strptime(row['start_time'], '%H:%M')
178
       st            = Time.strptime(row['start_time'], '%H:%M')
179
       a.start       = Time.zone.local(sd.year, sd.month, sd.day, st.hour, st.min)
179
       a.start       = Time.zone.local(sd.year, sd.month, sd.day, st.hour, st.min)
180
 
180
 
181
       if row['end_date'].present?
181
       if row['end_date'].present?
182
-        ed          = Date.strptime(row['end_date'])
182
+        ed          = Date.parse row['end_date']
183
         et          = Time.strptime(row['end_time'], '%H:%M')
183
         et          = Time.strptime(row['end_time'], '%H:%M')
184
         a.end       = Time.zone.local(ed.year, ed.month, ed.day, et.hour, et.min)
184
         a.end       = Time.zone.local(ed.year, ed.month, ed.day, et.hour, et.min)
185
       end
185
       end
186
 
186
 
187
       if row['deadline_date'].present?
187
       if row['deadline_date'].present?
188
-        dd            = Date.strptime(row['deadline_date'])
188
+        dd            = Date.parse row['deadline_date']
189
         dt            = Time.strptime(row['deadline_time'], '%H:%M')
189
         dt            = Time.strptime(row['deadline_time'], '%H:%M')
190
         a.deadline    = Time.zone.local(dd.year, dd.month, dd.day, dt.hour, dt.min)
190
         a.deadline    = Time.zone.local(dd.year, dd.month, dd.day, dt.hour, dt.min)
191
       end
191
       end
192
 
192
 
193
       if row['reminder_at_date'].present?
193
       if row['reminder_at_date'].present?
194
-        rd            = Date.strptime(row['reminder_at_date'])
194
+        rd            = Date.parse row['reminder_at_date']
195
         rt            = Time.strptime(row['reminder_at_time'], '%H:%M')
195
         rt            = Time.strptime(row['reminder_at_time'], '%H:%M')
196
         a.reminder_at = Time.zone.local(rd.year, rd.month, rd.day, rt.hour, rt.min)
196
         a.reminder_at = Time.zone.local(rd.year, rd.month, rd.day, rt.hour, rt.min)
197
       end
197
       end