moment end of the day add timezone - react-native

We have a react native application which using worldwide
I want to show end of the day as utc but cant figure out how to do that.
lets say my time zone is +03:00, so when utc enters the new day my local time should be 03:00, right? How can i show that value?
tried these
moment().utc().endOf('day').format() // -> 2023-02-16T23:59:59Z
moment().utc(true).endOf('day').format() // -> 2023-02-16T23:59:59Z
moment().endOf('day').utc().format() // -> 2023-02-16T20:59:59Z
moment().endOf('day').utc(true).format() // -> 2023-02-16T23:59:59Z
moment.utc().endOf('day').format() // -> 2023-02-16T23:59:59Z
// i need this 2023-02-17T02:59:59Z
How can i add that timezone offet to date without using moment-timezone

fixed like that
const date = moment().utc().endOf('day').toDate()
moment(date).utc(true).format() // -> 2023-02-17T02:59:59Z

Related

Why are the minutes disabled in vue-ctk-date-time-picker?

I am using the vue-ctk-date-time-picker to display a date time picker modal where users can pick date and time. I use a minDate such that users cannot pick date and time less than the current date and time. This works perfectly with format YYYY-MM-DD HH:mm:ss, but I needed the AM and PM format so I changed the format to YYYY-MM-DD HH:mm a. Now, the PM equivalent of the AM date is also being disabled.
For example, its 8:30 AM, so the picker disables all minutes upto 30 and users can only select 31, 32 and so on. But if I select PM, the minutes are still disabled, ie, the users are only able to pick from 31, when its not even PM yet.
Has anyone faced this problem? Is there a problem with package itself?
For anyone else having this problem, this is the solution according to the document here: https://github.com/chronotruck/vue-ctk-date-time-picker#behaviour
In order to avoid having too much properties in the component, We're
adding a behaviour property that is an object including some annex
behaviour values.
The default value for this object is:
{
time: {
nearestIfDisabled: true;
}
}
To override those values, pass a new object with the values you want
to override:
<ctk-date-time-picker
:behaviour="{
time: {
nearestIfDisabled: false
}
}"
/>

Kotlin: Store current date in Firestore as timestamp

Not sure why I can't find what I'm looking for. But I just want to store the current time into a Firestore document like this:
. In Flutter we just do this:
'timestamp': DateTime.now()
I tried doing this in kotlin:
"timestamp" to LocalDateTime.now()
But it gives me some complicated field:
The best way on all platforms is to use the server timestamp token provided by the SDK (and not using the client's clock, which could be wrong).
The documentation is here.
// Update the timestamp field with the value from the server
val updates = hashMapOf<String, Any>(
"timestamp" to FieldValue.serverTimestamp()
)
docRef.update(updates).addOnCompleteListener { }
If you really do want the client clock's time, just pass a java Date with Date() or Timestamp with Timestamp.now().

Swift 3 playground logs dates in local format. How?

If you run a line like this in a Playground in the US:
let today = Date()
You'll see output like this to the right of the source code:
"Sep 26, 2016, 8:17 PM"
That appears to be the date, displayed in the local time zone, using medium date and time style.
How does that work?
If you try to print the date:
print("today = \(today)"
You'll see "Today = 2016-09-27 00:18:55 +0000\n", which is UTC, and appears to be unix date format.
What function is the Playground using to display the date when you first create a date? Is there a way to get to that output format from code or from the debug console?
Up until now I've created a date formatter that I use to log dates, display them in the console, etc.
It's lurking in CustomPlaygroundQuickLookable protocol, which Date conforms to:
if case .text(let str) = today.customPlaygroundQuickLook {
print(str)
}

Google BigQuery seems to run in the Pacific Time zone not UTC. Is there any good reason for this? Is there any way to change it?

UDF:
bigquery.defineFunction(
'newdate', // Name of the function exported to SQL
[], // Names of input columns
[
{name: 'date', type: 'timestamp'}
, {name: 'datestr', type: 'string'}
],
function newDate(row, emit) {
var date = new Date(); // current date and time
emit({
date: date
, datestr: date + ''
});
}
);
SQL:
SELECT date, datestr
FROM (newDate(SELECT "ignored" AS inputA))
Output:
1459282876835809 Tue Mar 29 2016 13:21:16 GMT-0700 (PDT)
That's an unfortunate oversight on our part.
Many Google servers run using Pacific time (semi-jokingly referred to as "Google standard time"). When launching BigQuery, we tried to standardize on UTC instead, but we missed this case. We may try to find an opportunity to fix it, but unfortunately we risk breaking existing users if we do so, so no promises.
Thanks for the heads up!
Don't know rationale for running in Pacific time zone, but you just ignore the system time zone, and use UTC time in your code.
E.g. use datestr: date.toUTCString() instead of datestr: date + ''.

Rails 3.2.8 - How to handle Time zones?

I've participated the Rails Rumble this year and I found myself tangled by time zone issues.
I uploaded my app in linode and I live in EST time zone or -4 to UTC.
I have a model and it saves things by doing the following:
def self.processing_creation(user_id, home_id, chore_id)
registered_chore = RegisteredChore.where("DATE(created_at) = ?", Date.today).find_by_user_id_and_home_id_and_chore_id(user_id, home_id, chore_id)
unless registered_chore
registered_chore = RegisteredChore.create(user_id: user_id, home_id: home_id, chore_id: chore_id, created_at: Time.zone.now)
user = registered_chore.user
user.add_one_chore_point
end
registered_chore
end
RegisteredChore.where("DATE(created_at) = ?", Date.today).find_by_user_id_and_home_id_and_chore_id(user_id, home_id, chore_id)
returns false even if the data was just created.
I noticed that "create" saves in UTC but Date.today uses user's local time zone.
What's the best way to handle this?
Another example to illustrate the issue:
I want to register a chore at 11 PM in EST time.
The server is already in the next day (e.g: 12).
Rails saves the data in the next day date (12).
But user is still in day 11.
Technically, user with the current method, could save the entry again because the days are different from the db and user interface.
How to solve this?
Rails will, by default, save times to the database as UTC. If you're using DATE([Date.today]), then it's going to be looking up records on the 11th, not the 12th. To get the right date, you probably want to set Time.zone to the user's current timezone, and then do the query.
I built a gem called by_star to handle this kind of date searching, and I reckon you should use it. With it, your query would be this:
RegisteredChore.today.where(:user_id => user.id,
:home_id => home.id,
:chore_id => chore.id)
Rails 3 by default saves all the time in database relative in GMT+00:00 time zone. So you will have to set an offset while computing time depending on your timezone. Else, you can change default Activerecord time zone by adding following to application.rb
config.time_zone = 'Your time zone' (Example: 'Eastern Time (US & Canada)')
config.active_record.default_timezone = 'Your time zone' (Example: 'Eastern Time (US & Canada)')