Do you know if there is a way to write "set time zone interval '00:00' hour to minute" inside create view code? I`ve been finding ways on how to do it because I cannot change the default time zone setting of a user or ask him to change the current time zone setting every time he select a view table.
Related
I have a json object and in that I have date and time and want that date and time to be set automatically meaning it should read computer's date and time automatically every day when the application is in run? Can anyone help how to do that?
I don't have any solution for this.
I am building an event reminder page where people can set a reminder for certain events. There is an option for the user to set the amount of time before they need to be notified. It is stored in notification_time and notification_unit. notification_time keeps track of the time before they want to be notified and notification_unit keeps track of the PHP date format in which they selected the time, eg. i for minutes, H for hours.
Eg. notification_time - 2 and notification_unit - H means they need to be notified 2 hours before.
I have Cron jobs running in the background for handling the notification. This function is being hit once every minute.
Reminder::where(function ($query) {
$query->where('event_time', '>=', now()->subMinutes(Carbon::createFromFormat('i', 60)->diffInMinutes() - 1)->format('H:i:s'));
$query->where('event_time', '<=', now()->subMinutes(Carbon::createFromFormat('i', 60)->diffInMinutes())->format('H:i:s'));
})
In this function, I am hard coding the 'i', 60 while it should be fetched from the database. event_time is also part of the same table
The table looks something like this -
id event_time ... notification_unit notification_time created_at updated_at
Is there any way to solve this issue? Is it possible to do the same logic with SQL instead?
A direct answer to this question is not possible. I found 2 ways to resolve my issue.
First solution
Mysql has DATEDIFF and DATE_SUB to get timestamp difference and subtract certain intervals from a timestamp. In my case, the function runs every minute. To use them, I have to refactor my database to store the time and unit in seconds in the database. Then do the calculation. I chose not to use this way because both operations are a bit heavy on the server-side since I am running the function every minute.
Second Solution
This is the solution that I personally did in my case. Here I did the calculations while storing it in the database. Meaning? Let me explain. I created a new table notification_settings which is linked to the reminder (one-one relation). The table looks like this
id, unit, time, notify_at, repeating, created_at, updated_at
The unit and time columns are only used while displaying the reminder. What I did is, I calculated when to be notified in the notify_at column. So in the event scheduler, I need to check for the reminders at present (since I am running it every minute). The repeating column is there to keep track of whether the reminder is repeating or not. If it is repeating I re-calculate the notify_at column at the time of scheduling. Once the user is notified notify_at is set to null.
I am using Odoo sequence for a form number. This sequence is set to reset every month. But I have noticed an issue in the sequence reset time.
The sequence turns out resetting every UTC not at server timezone which is UTC +8. So when a transaction happened at 1 July 7 AM (UTC + 8) the sequence is still not being reset. The reset happened on 1 July at 8 AM (UTC).
How can I make the sequence reset based on my timezone? The server timezone is already UTC + 8.
Two Options:
Check the timezone of your database. Do this in your postgres db terminal with the command:
show timezone;
You should expect your local timezone or UTC
If you check the model behind the feature, in the postgress console:
\d ir_sequence_date_range
You may notice that the fields related to the range of the dates (date_from, date_to) were created as "date" and not "datetime" so it gonna miss the hours.
Also, in the form view, the is not possible to set the time:
sequence_form
So an alternative is change the data type of the column from date to datetime. To do this you must extend the model and over write the field something like this:
class IrSequenceDateRangeExtended(models.Model):
_inherit = 'ir.sequence.date_range'
date_from = fields.Datetime(string='From', required=True)
date_to = fields.Datetime(string='To', required=True)
Then, after update you should be able to set the time to the date.
I hope it helps you.
I am storing all dates to SQL Server as a UTC date time. I have Time Zone Id for each user stored in user profile as well.
Now when user requests data back, I want to display local time of user for each record using the Time Zone I have stored in profile for the particular user.
What is an easiest and optimized way (as I am processing heaps of records at the same time) to convert all dates and time to particular time zone on the fly while returning data? Either in SQL or in C# would be fine...
Very important question is, let's say there is a record created from Sydney when there was Day Light Saving "ON" and now Day Light Saving is "OFF". As the record was created when Day Light Saving was "ON", will it still convert the same time or will it return conversion as per current time zone status (which is Day Light Saving is "OFF")???
People only see those records which they had created from the particular
let's say there is a record created from Sydney when there was Day Light Saving "ON" and now Day Light Saving is "OFF". As the record was created when Day Light Saving was "ON", will it still convert the same time or will it return conversion as per current time zone status (which is Day Light Saving is "OFF")
The record contains an UTC date and time. This is going to fall into a DST ON or DST OFF period, deterministic. Is irrelevant whether the DST is in effect now. The opposite (storing local time, trying to extract UTC) is undetermined because of the overlap times when the DST changes (a small range of local times cannot be deterministically converted to UTC if they fall into the 60 mins that occurs twice when DST come into effect, assuming a 60 min DST).
As for the question: transform the date in your presentation layer. Use TimeZoneInfo.ConvertTimeFromUtc.
why NSDatePicker is changing its datevalue on changing the timezone? and how to prevent the change of datevalue of date picker.
I Know if we set the timezone of 'datepicker' it doesn't change,My exact requirement is,what ever the time zone the time of 'datepicker' as well as the time of the date component should not change But at the same time the application should follow the changed 'timezone'
My Exact requirement is at any timezone the operation should perform at particular.but the time of the datepicker should not change at the same time the application should follow the current timezone.
Thanks in advance
you will have to observe NSSystemClockDidChangeNotification, see:
How can I get notified of a system time change in my Cocoa application?
then you will have to calculate the new date and set it in the NSDatePicker.
or alternately you can set the time zone of the picker, so that it doesn't use the auto updating current locale.
it depends on what you hope to achieve, as the first one will change the date value, the second will just freeze the view layer in a particular time zone.