F
Filament17mo ago
Saade

DatePicker creating records wrongly but editing correctly

I have an app configured with UTC timezone, and form with the following date picker (DATE ONLY, no time):
Forms\Components\DatePicker::make('start_date')
->label('Data de início')
->timezone('America/Sao_Paulo')
->required(),
Forms\Components\DatePicker::make('start_date')
->label('Data de início')
->timezone('America/Sao_Paulo')
->required(),
If i select 2023-03-09 in the form, it CREATES in the database as 2023-03-09 (wrong, it should save as D-1) If i view the record, it will show as 2023-03-08 (wrong, because of timezone) Then i edit this date back to 2023-03-09 and it UPDATES to 2023-03-10 (correct, D-1) If i view the record, it will show as 2023-03-09 (which is now correct) WTF is going on? Am i dumb and don't know how timezone works?
13 Replies
Saade
Saade17mo ago
Ok, looking through some issues, i found timezone() method is not appropriate for use on a date-only input - only time. which makes sense (duh). But the date still jumps back 1 day while creating, but not when saving, what is going on in this case?
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
awcodes
awcodes17mo ago
Is it cast as a datetime?
Saade
Saade17mo ago
date
awcodes
awcodes17mo ago
That’s the only thing I could think of. Sorry.
Saade
Saade17mo ago
btw, i have separated columns for start_date start_time end_date end_time i dont really know to to compute timezones when using separated fields with start_time and end_time being nullable
awcodes
awcodes17mo ago
Yea. That’s tricky. The date is whatever they enter. Do they need to be separate in the datebase? If the time is null it’ll just default to 00:00:00
Saade
Saade17mo ago
but then how do i deferentiate 2023-03-10 00:00:00 "today with null time" from "today at midnight"? its an "event in the calendar" which an event can have an start time or not
awcodes
awcodes17mo ago
I’m not sure. Just trying to think of options.
Saade
Saade17mo ago
its ok 🙂 Maybe Zep can help in some way, lets see if he shows up in here
Thijmen
Thijmen17mo ago
Why do you need the timezone? Because timezones only apply to times and not dates i am not sure i understand your use case. The difference between utc and sao paulo is like 5 hours. So the only time when UTC and Brasil time are different is in the last 5 hours of Brasil time. So if a brasilian user selects the date 2023-03-10 on 10:24 that will also be 2023-03-10 on UTC time. I think the create is not timezone based. Only the select is rendering the different date and then it is changed because the select states a new date
wyChoong
wyChoong17mo ago
In my case of just using without time, I store start date and end date. And when using it, then set the time to 00:00 and 23:59 respectively , then I can get the range of start date time to end date time for same day or more than a day event
Saade
Saade16mo ago
Hi, thanks for the response America/Sao_Paulo has a 3 hour difference (UTC-3), therefore if i select 2023-03-10 on 10:24pm in America/Sao_Paulo it will be 2023-03-11 on 01:24 in UTC in that example i need to add +1 day to the date
Want results from more Discord servers?
Add your server
More Posts
How do I add "forgot password" link to login page?How do I add "forgot password" link to login page?Grouping form fields to reuse them in different formsIs it possible to make a group a f.e. 5 form fields and save them in a "file". And reuse them in sevIs there a way to auto-scrub model attributes that aren't being used?Hello, according to https://filamentphp.com/docs/2.x/admin/resources/security, filament automaticallhow to make uploaded image only visible inside the filament admin panelI have a filament form outside the admin panel where fotos can be uploaded. What do i have to do thaMissing sidebar menu nav``` Alpine Expression Error: Cannot read properties of null (reading 'includes') Expression: "! ($sIs there a way to display no records in the list view by default and only see records when searchin?I want to make it so that: User accesses list records page -> User sees 0 records by default -> UsemutateFormDataBeforeCreate vs dehydrateStateUsingAre they kind of interchangeable? I understand that one is specific to create, but in general, couldModel Policies and AdminIf Im restricting access to the admin to a few select users using canAccessFilament(), do I need to Error when prefilling from query string in resource with persistTabInQueryString enabledHi, I get the following error when persisting tabs in query string enabled when creating a form or uUse createOptionForm and createOptionAction in Radio FieldHow we can use createOptionForm and createOptionAction in Radio Field?