Thanks very much @meredydd - this is getting more confusing now, so I"m going to work through it here, hopefully with screenshots and let’s see if we can get to the bottom of it.
I repeat, I’m not looking for a code fix, I’m just trying to understand what is happening to the timings/timezone data.
I made an entry in Spain at 08:42 on 18/10 for a diary entry of the 15/10
The data is captured from a simple user form on the client app, using a datepicker object with time_picker enabled. No other settings or special anvil.tz() stuff.
I then create a new article in the client form code, to send to a server function so that it can be written to the data table. The important bit of the client side code looks like this:
new_article={'DOSE_DATE_TIME':self.dose_date_pkr.date,
I then call a server function from the client to save the new article to the datatables
result=anvil.server.call('add_article_daily_diary', new_article)
That server function looks like this:
# add a row to T_DIARY
@anvil.server.callable
def add_article_daily_diary(article_dict):
me=check_user()
# I've snipped some code out of this function, so that I don't fill up the forum post
# nothing there that messes with DOSE_DATE_TIME though
try:
app_tables.t_diary.add_row(
DOSE_DATE=DOSE_DATE,
PATIENT_ID=me['PATIENT_ID'],
CREATED=datetime.now(),
CREATOR=me['email'],
STUDY_SITE=get_patient_study_site(),
LATEST=bool(True),
STEP=str(step),
**article_dict)
val=True
except Exception as E:
print(f"Boz in ServerMod add_article_daily_diary. Error is {E}")
val=False
return val
Just a simple add_row() function.
The data is stored in a datatable and looks like this
As you can see, we have a CREATED timestamp and a DOSE_DATE_TIME, which is the local timestamp when I was in Spain. All as expected so far.
Note: Within the data table, the DOSE_DATE_TIME column is of datatype (date and time)
Viewing the data when back in the UK
In the client app, I have a form with a repeating_panel in it.
Each row in the repeating_panel is a card, and has several elements…including an edit button…
It looks like this
We are interested in the row with the Date 15-10-2024
I load the items into the repeating_panel by calling a server function like this:
self.repeating_panel_1.items = anvil.server.call('get_all_user_diary_entries')
And here is the server side function:
This function just returns the search results ordered by a different column (DOSE_DATE)
I’ve put a debug line into the server function, and here are the results
BOZ in get_all_user_diary_entries and CREATED is: 2024-10-18 06:42:29.914064+00:00 and DOSE_DATE_TIME is: 2024-10-15 10:42:00+02:00
So, the server function is amending the DOSE_DATE_TIME as it transfers that information back to the client… It is saying 10:42+02:00
This 10:42 now gets changed to 09:42 when I display it in the client app:
Now when I click the edit button in my repeating panel I populate a hidden linear panel with the original form used to capture the data from the user in the first place, and populate the fields so they can edit them…
The important part of that edit_btn code is below, and I’ve whacked a debug line in there
def edit_btn_click(self, **event_args):
# Open an alert displaying the 'ArticleEdit' Form
article_copy=dict(self.item) # grab a copy of the rows values
orig_copy=self.item
print(f'boz self.item is of type {type(self.item)}')
print(f'BOZ in diary_view_copy and datetime is set to: {article_copy["DOSE_DATE_TIME"]}')
....
In the console I get the following output:
BOZ in diary_view_copy and datetime is seet to: 2024-10-15 10:42:00+02:00
So I think this is where the browse locale is kicking in for the datetime object.
Here is a screenshot of the client app when the edit_btn has been clicked
So I guess my question is as follows:
if the data in the table is 08:42+0200 from UTC, why is a search returning 10:42+02:00? Something is then displaying it as 09:42 (see above)
Sorry for the very long response…it has been good to identify where the issue is coming from though.
Cheers
Boz