Convert UTC date to user's timezone in email message - email

I'm building a site that stores date/time values in UTC on the database.
When I display these values, I use javascript to convert them to the current's user timezone. This is working correctly so far.
Now I want to send some information to users by email (something like a reminder), and this should have the date time as well.
I don't want to print the UTC time in the email, and since I'm sending the email from the server I don't have access to the user's current timezone.
What's the best approach to solve this? should I store the timezone of the user whenever he logs in and use that to convert the date?
Any comments are appreciated.

Yes, you can detect the user's timezone using Javascript, have the Javascript submit that information to the server, and have the server store it as a preference. If the user sometimes changes timezones you could even keep track of which one they are in most frequently and use that one.

Related

Email reminders - correct timezone

I want to send email reminders to users and include the date and time in the email itself. How do I make sure that those are displayed in a user's current timezone, especially when the user might have traveled in the time he saved the record in the database?
Is the only way to just display the date in the email and include the timezone next to it?
Twilio SendGrid developer evangelist here.
When you send an email to a user, unless it is in response to a request that includes the user's current time zone, you cannot know for sure what time zone they are in. So, your suggestion to include the time zone in the date and time is a good idea.
One other suggestion is that you could send them an attachment with a calendar invite that includes the time of the event in UTC that can then be read and displayed by their calendar application in their own time zone.

Exchange Online: Changing timezone for meeting hours?

When updating mailbox timezone in Exchange Online with Set-MailboxRegionalConfiguration, the timezone changes correctly but checking the mailbox through the OWA gui reveals that meeting hours have not changed to match, requiring a manual step by the user.
Message reads:
The current zone for your meeting hours is [timezone]
and is asking if the user is going to remain in the new timezone and to change the meeting hours to match.
Is it possible to set the meeting hours via Powershell?
If anyone comes across this, we ended up using the Graph API to amend this

How do Setup Tableau extract refresh

How to the setup or configure my extract filters in tableau to always load the current data when admin refreshes the extract
If you want the user to be shown the latest data upon every refresh on the dashboard, you will need to use MAX in your worksheets. For example: When the user opens the dashboard, the user is prompted automatically with week 05, next week when you refresh the data extract on server, the user is prompted with week 06. In that scenario, you dont need to change filter or parameter, it is automatic.
There are drawbacks to the use of Max everytime. In some of your worksheets you might not have Week 05 data because of other filters. It returns you Max week to be 03 because you have data for that week. Should be careful and test more when using LODs

What is the right way to keep the information between my bot and Facebook consistent?

From what I read in the Facebook Messenger documentation, there are a couple of callbacks that are triggered. The onReceivedAuthentication() as per documentation is called when a person taps on the "Send to Messenger" plugin. I want to save the person's firstName, lastName, picture and gender in my database. What if the person directly searches for our page and starts chatting with it? In that case, the above callback won't be triggered right? What if the user changes their name or picture on Facebook? How do I keep my database consistent with Facebook's data for each user?
Currently, I am updating the person's details in my database everytime the user greets my bot. I don't think that is a good strategy. Any suggestions are appreciated.
Just decide particular time limit like 1 hour or 24 hours or 1 week or as per your choice and when you store user's data from facebook by its graph API response,store one more field for that particular time of storing it either by timestamp or date and after that whenever you get message from user just compare that messages' timestamp with that field and if that difference is greater than that decided time limit then update users' data.
you can compare user's current message time as you are getting it in form of timestamp with every message
Hope this help you.

HOWTO remove device tokens received by Apple APNS feedback

I am successfully fetching Apple APNS feedback data via PHP. The structure that I am getting (after some processing) looks something like this:
timestamp
device token
My question is how to know which of the device tokens should I remove from my database and stop sending notifications to them.
Regardz,
Mladjo
The timestamp is the crucial element here. The timestamp sent by Apple indicates the last time the push service attempted to deliver a message to the device and found the app to be uninstalled. If the device has re-registered with your service since then there is no need to delete it.
Therefore, every single time your app loads and sends the token to your service, you should log the time in your data store. When you run feedback you should check the time from Apple and compare it to the time you last received an update from the app on the device. If the time Apple sends is newer then the time you received an updated then you should delete (or disable) the device. If the time from Apple is earlier then you do not need to delete it because the user has reinstalled the device since Apple last tried to deliver.
All devices given by feedback are 'failed' and should be removed. No feedback means no devices should be removed. It's covered over on the Apple Documentation:
Apple APN Documentation
neat explanation #argon, however I have another question about the timestamp.
Every time when an app enables push notification, the device token is sent to the server. Should I taken the timestamp from my server as to be persisted along with device token as didRegisterForRemoteNotificationsWithDeviceToken only gives deviceToken and not time. If my server runs in different timezone and APNS is running at different timezone, then the registration time stored( along with device token) cannot be compared with timestamp received from APNS feedback to check the sequence of register -> uninstall -> reregister.
I presume the APNS feedback timestamp is in UTC and the timestamp the server stores along with device token has to be converted to UTC before storing the ISO timestamp. This way both the timestamp will be in same timezone and diff check will be consistent.
please clarify
#fyasar,
So your recommendation is to store the device token against device id(or some key). When a feedback is received for a device token, remove that device token row from DB, right? If have understood right, that wouldn't work in scenario were a user installs app, uninstalls it and then installs it again all with in a short duration and the feedback service was queried only after all this happened. In this case, if timestamp in feedback is not considered, device token will be removed which is incorrect as user has again installed the app and reregistered for push notification.
My question is this, as suggested in apple doc and many blogs, on registration, when device token is persisted, timestamp has to be persisted along with it. What time zone's ISO time should be persisted or what is the time zone on which feedback service returns the timestamp.
A timestamp (as a four-byte time_t value) indicating when APNs
determined that the app no longer exists on the device. This value,
which is in network order, represents the seconds since 12:00 midnight
on January 1, 1970 UTC.
you can compare it with your table's last insert time and then remove the invalid token from db, In my case i am using mysql and php for sever side
$sql="SELECT insert_time from device_tokens ORDER BY insert_time DESC LIMIT 1";
it will return last updated time from db and then i just convert it into epoch timestamp by using
$sql1="SELECT UNIX_TIMESTAMP(' $timestamp')";
and finally i just compare it with apns feedback timestamp like this
if($inactive_Timestamp>$dbTime_stamp)
{
foreach ($apnsfeedback_tokens as $key => $value) {
# code...
$inactive_Token=$value['devtoken'];
$sql= "DELETE FROM device_tokens WHERE device_token='$inactive_Token'";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
You should store devices with their device token data, and then you can find these devices according to their device tokens. You might use device token for identifier each device. Than would be easy to find and change their statuses into your db.