Scheduling events with changing Time zone - datetime

I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else

Related

Override default date rage for DayGridMonth view

I have been looking high and low and so far have seen no options via the code or anything else that seems to even come close to what i am asking. My request is simple enough. Typically when we want to display in a month grid view the month of September 2019 we expect the start of this month to be 9/1/2019 and the end to be 9/30/2019 with anything before or after to be considered other month.
However, I need for my calendar to have a different date range for the month of September 2019. This is so that it aligns with how we manage months. With the exception of the month of October all other months of the year are modified for different date range.
January = 01/01 to 01/30
February = 01/31 to 03/01
March = 03/02 to 03/31
April = 04/01 to 05/01
May = 05/02 to 06/01
June = 06/02 to 07/01
July = 07/02 to 07/31
August = 08/01 to 08/30
September = 08/31 to 09/30
October = 10/01 to 10/31
November = 11/01 to 12/01
December = 12/02 to 12/31
In many cases I do not need to make many adjustments (just some add/remove "fc-other-month" class, as the previous months ending dates are also visible (if using the 6 week enabled flag, which is also set by default), however, in September 2019, 09/01 is on a Sunday of the first week meaning that the previous week that would include 8/31 is not rendered.
I can explore a "brute force" type method of checking for this condition and then prepending another row on top of week 1 with the additional dates needed but I have to believe that there is a simple method where i can simply state the months start and end date range.

Cloud Firestore: query for an item's availability given a timestamp

Imagine an Airbnb like app. A rentals collection contains documents with fields start and end of type timestamp that records the start date and end date of the rental (year, month and day only). Inside my Flutter app, when a user wants to make a new rental request, I need to check if the request interferes with any existing rentals. Would it be too much to store an array of Timestamp objects that contain the amount of days, then use arrayContains to query/check?
For example:
rental #1
start: Jan 1
end: Jan 2
days: [Jan 1, Jan 2]
rental #2
start: Jan 6
end: Jan 10
days: [Jan 6, Jan 7, Jan 8, Jan 9, Jan 10]
Suppose the user wants to book a rental for Jan 3-4. I would run a loop and query for documents with arrayContains: Jan 3 and arrayContains: Jan 4 and if it returns any documents, then I know the rental request date is invalid. The maximum amount of days a user can rent is 27 days, although I expect the average rental duration to last under 7 days. Is my method viable? I could change the maximum rental duration from 27 to 14 possibly.
The other method I came up with is to query for the rentals immediately before and after the desired pickup time. So using the above example, if my desired rental date is Jan 3-4, I would query for the closest rental that ends before Jan 3 and the closest rental that starts after Jan 4. However, the issue I'm running into is what if the user in rental #1 decides to extend their rental from Jan 1-2 to Jan 1-3 (before our user is able to refresh their app)? Or if a particular listing has no rental history associated with it.

How to getValue() on a date with the correct TimeZone?

Someone in the "Europe/London" (UTC +0) Timezone created a Spreadsheet. They input the date "March 22 2019" into one of the fields. This represents the date 3/22/2019 0:00 UTC+O.
I'm in the "America/Los_Angeles" (UTC -7) Timezone. When I run a Google Apps Script and try to get the value, it's evaluated as:
Thu Mar 21 17:00:00 GMT-07:00 2019
This is accurate since 3/22/2019 0:00 UTC+O == 3/21/2019 17:00 UTC-7.
The problem is when I try to get the date programmatically, I'll get it as 21 instead of 22.
For example, if I try to run:
cellRange.getValue().getDate() // returns 21 even though the sheet shows the date as 22
This is because getDate() returns values "according to local time." The local script time is UTC-7, hence it's returning 21.
However, this causes a dissonance:
Spreadsheet date: 22 (i.e. the value I see in the sheet)
Programmatic date: 21 (i.e. the one returned by getDate() above)
This is problematic when I'm trying to use a function such as joinDateAndTime_() with "March 22 2019" as the date and 6am as the time, for example. This causes it to produce a date "March 21 2019 6:00 UTC-7" instead of "March 22 2019 6:00 UTC-7".
What is the best solution here?
Not a complete solution (I'll update soon)
It seems like this is what is happening:
The value is hard-coded as "March 22" (text).
When a user opens the sheet, no matter what timezone they are in, it'll assume it represents March 22 in the sheet's timezone. 3/22/2019 0:00 UTC+0
Once you read the value into a JavaScript Date, all date functions assume you want it in your current (aka the script's) timezone. 3/21/2019 17:00 UTC-7
Solution A: Just add the hours
Forget about the timezones. Instead of hardcoding the hours in a Date, just offset the date by the hours you want.
The only downside is you need to be certain that the date started at 0:00 according to whatever timezone it was in. (E.g. if they decided to write "March 22 2019 5:00", then you'll be offsetting the hours incorrectly.)
Solution B: Do some math
I'll update this soon, but eventually you might want a function sheetTimezoneOffset() that could be used like this:
function getDate(cellRange) {
var date = cellRange.getValue().getDate();
var extraneousHours = formatDate(date, "h", sheetTimezoneOffset());
date = date.addHours(-extraneousHours);
var offsetHours = 6; // e.g. for 6am
date.addHours(offsetHours);
return date;
}

What does the last number in UNIX timestamp mean?

I have a few UNIX timestamps that I've been converting back and forth, and I notice that the last number of the timestamp would change without causing any difference in the date.
For example, if you convert this number to normal date:
1452120848 > 6-1-16 17:54
But if you convert it back:
6-1-16 17:54 > 1452120840
As you can see the last number was changed to a zero. I tried some of the online converters and discovered that the last number could be any number and the date wouldn't change. What does it mean?
The unix time is the time in seconds since 1970.
You don't convert the seconds part of your date, thus it's 'lost' - your numbers may differ by up to 60.
The timestamp of 1452120848 is actually: Wed Jan 6 22:54:08 2016
So you're missing 8 seconds.
The UNIX timestamp gives you the seconds since 1st January 1970 00.00.00 UTC. Since this is seconds and you are just printing up to minutes, the difference is not shown.
However, they are not the same date:
$ date -d#1452120848
Wed Jan 6 23:54:08 CET 2016
$ date -d#1452120840
Wed Jan 6 23:54:00 CET 2016

understanding epoch time to calculate password ageing in unix

my_current_epoch=15684 equivalent time stamp is Thu, 01 Jan 1970 04:21:24
last_password_reset_epoch_time=15547 equivalent time stamp is Thu, 01 Jan 1970 04:19:07
I am not able to understand how difference of these two will give the days since last password reset.
As per my understanding epoch time is denoted in seconds that has elapsed since Jan 1,1970
Can someone please help me understanding this.
man 5 shadow on a Linux box says:
The date of the last password change is given as the number of days since Jan 1, 1970. The password may not
be changed again until the proper number of days have passed, and must be changed after the maximum number
of days. If the minimum number of days required is greater than the maximum number of day allowed, this
password may not be changed by the user.
So, you can find out to within 24 hours when a password was changed by multiplying the value from /etc/shadow by 86400 (the number of seconds in a day — but you didn't need me to tell you that, did you?).
For the values given (bc to the rescue):
15684*86400 = 1355097600
15547*86400 = 1343260800
And:
$ timestamp -u 1355097600 1343260800
1355097600 = Mon Dec 10 00:00:00 2012
1343260800 = Thu Jul 26 00:00:00 2012
$
Timestamp is my program; modern versions of date can handle this too. The -u means 'report in UTC (aka GMT)' rather than in my time zone.
"epoch" value in /etc/shadow = 15684
the seconds in 24 hours (because normally "epoch" value shows in seconds but for some reason (to make compact view, maybe) in /etc/shadow file "epoch" value displays in days, not in seconds) = 24 * 60 * 60 = 86400
And by multipliying these two numbers: 15684 (days) x 86400 (seconds per day); we will get the number 1355097600.
Afterwards, either using Epoch Converter by copy/paste the final result, you can get the date, or
just use date --date #$(( 15684 * 86400 )) command in cli

Resources