IFB-ElixirFr / ifbcat

IFB Catalogue REST API.
GNU General Public License v3.0
1 stars 0 forks source link

Imports for dates remove 1 day #140

Closed guillaumecharbonnier closed 2 years ago

guillaumecharbonnier commented 3 years ago

I have noticed the dates are shifted by 1 day when imported with the code chunk in load_events.csv and load_training.csv (the same code chunk pasted below).

Here is an example for the training named "Formation librairie GATB" from events.csv | 15/6/2017 from load_events | 2017-06-14 from training.csv | 16-06-2017 from load_training | 2017-06-15

Note the dates for the (very likely) same event are also not the same when exported from Drupal to events.csv and training.csv, meaning it is not straightforward to update the same training events when importing training.csv after events.csv. The easiest solution may be to work on Drupal table export to get a clean and complete table for trainings with all infos currently disseminated through events.csv and training.csv.

                if data_object[3]:
                    if "to" in data_object[3]:
                        event_start_date = datetime.datetime.strptime(
                            data_object[3].split(" to ")[0], "%d-%m-%Y"
                        )  # .strftime("%Y-%m-%d")
                        event_start_date = make_aware(event_start_date, timezone=pytz.timezone('Europe/Paris'))
                        event_end_date = datetime.datetime.strptime(data_object[3].split(" to ")[1], "%d-%m-%Y")
                        event_end_date = make_aware(event_end_date, timezone=pytz.timezone('Europe/Paris'))
                    else:
                        event_start_date = datetime.datetime.strptime(
                            data_object[3], "%d-%m-%Y"
                        )  # .strftime("%Y-%m-%d")
                        event_start_date = make_aware(event_start_date, timezone=pytz.timezone('Europe/Paris'))
                        event_end_date = None
                else:
                    event_start_date = None
                    event_end_date = None
bryan-brancotte commented 3 years ago

Hi @guillaumecharbonnier

I applied ba2a767 and it appears to have solved the issue. Instead of giving a date instance to the orm, I give it the date as string in the format it wants, and works like a charm.

About to do the same for training

guillaumecharbonnier commented 3 years ago

Hi @bryan-brancotte Thanks for the solution. I can apply the fix for training. You should know load_training.py diverged a lot in my branch from master if you are also tempted to update other parts of the file.

bryan-brancotte commented 3 years ago

Hi, indeed ! Here is the "patch"

from ifbcat_api.management.commands.load_events import parse_date
if "to" in data_object[7]:
    data_object[7] = data_object[7].split(" to ")
    formation_start_date = parse_date(data_object[7][0])
    formation_end_date = parse_date(data_object[7][1])
else:
    formation_start_date = parse_date(data_object[7])
    formation_end_date = None
bryan-brancotte commented 2 years ago

Hi @Aziguy could you check if it is still the case ?

Aziguy commented 2 years ago

Hi @Aziguy could you check if it is still the case ?

For items in events.csv all going well. However, for the items in training.csv date session is wrong (the system remove 1day each time).

I noticed that this function was 'nt used to parse training_start_date and training_end_date. I applied the parse and I think, all going well now.