From 2d35142ba2435cd403b220b6f7154bd1dea491bf Mon Sep 17 00:00:00 2001
From: Anusha Ranganathan <anusha@cottagelabs.com>
Date: Wed, 5 Feb 2025 11:42:11 +0530
Subject: [PATCH] Improved check for parsing incomplete dates in session date
 recorded

---
 ...0240724144034_change_date_recorded_type_string_into_date.rb | 1 +
 hyrax/lib/tasks/fix_complex_sessions_date_recorded.rake        | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hyrax/db/migrate/20240724144034_change_date_recorded_type_string_into_date.rb b/hyrax/db/migrate/20240724144034_change_date_recorded_type_string_into_date.rb
index 2354f7b5..a4010484 100644
--- a/hyrax/db/migrate/20240724144034_change_date_recorded_type_string_into_date.rb
+++ b/hyrax/db/migrate/20240724144034_change_date_recorded_type_string_into_date.rb
@@ -1,5 +1,6 @@
 class ChangeDateRecordedTypeStringIntoDate < ActiveRecord::Migration[5.2]
   def up
+    Rake::Task['rdms:fix_complex_sessions_date_recorded'].invoke
     add_column :complex_sessions, :session_date_recorded_temp, :timestamp
     change_column :complex_sessions, :session_date_recorded_temp, 'timestamp USING CAST(session_date_recorded AS timestamp)'
 
diff --git a/hyrax/lib/tasks/fix_complex_sessions_date_recorded.rake b/hyrax/lib/tasks/fix_complex_sessions_date_recorded.rake
index 3cb96311..120fe244 100644
--- a/hyrax/lib/tasks/fix_complex_sessions_date_recorded.rake
+++ b/hyrax/lib/tasks/fix_complex_sessions_date_recorded.rake
@@ -6,7 +6,8 @@ namespace :rdms do
       # Fixing date recorded for complex session
       puts "Fixing date recorded for complex session #{session.id}"
       begin
-        new_date = DateTime.parse(session.session_date_recorded).strftime('%Y-%m-%d')
+        dt = session.session_date_recorded.gsub('-', "/")
+        new_date = DateTime.parse(dt).strftime('%Y-%m-%d')
         session.update(session_date_recorded: new_date)
       rescue
         puts "error Fixing date recorded for complex session #{session.id}"
-- 
GitLab