I need to record my expenses from around the World on the same Spreadsheet (be able to write a date at local time in East Africa, a date at local time in Dubai, in Thailand...)
So, amongst all other data, I need to record:
- The date and time the transaction has taken place (I copy the shop receipt with date, time and amount) and time zone it has taken place at
- The date and time in the Time Zone of Rome which is my home time zone and so the bank account time zone
- The date and time the transaction is being recorded (timestamp at local time zone, i.e. the time zone of the place I find myself at while travelling)
The location where I perform actions at 1 and 3 may be different, for example, I may be located in Thailand and want to record an expense I made in the US (and translate into the time in Rome, which is the one always present).
I set the column A as a date using "Data validation..." There, I manually input the date of transaction picking from the popup calendar and I manually add the time (as per receipt). To the next column I manually set the time zone where I was when I made the transaction. I want to record in the Date of transaction column the date as it showed locally when I made it. So I would like to get a date made of that column and the next column which contains the time zone. But if I make a
transcationDateCell.getValue()
I get "November 22, 2016 18:59:51 +0100" which already includes a time zone (either the one where I am when the script runs or the one from the Spreadsheet Settings?) So I cannot use the manually set time zone.I used:
var tsTransDateRome = Utilities.formatDate(new Date(tsTransDateValue), "Europe/Rome", dateFormatString);
where
tsTransDateValue
contains the date set manually from the Spreadsheet UI as to point 1.I should be okay with this. It's automatically filled in via GAS. I used:
var timeZoneScript = Session.getScriptTimeZone(); // Check if when I travel to a different TimeZone it will adjust or if the ScriptTimezone keeps being the one when the SpreadSheet was created (File->Spreadsheet Settings) var tsTimeZoneRecCell = transSheet.getRange(tsActiveRowIdx, tsTimeZoneRecColIdx);
And I speculate that if I move to a different timezone my
Session.getScriptTimeZone()
will adjust to the local timezone (i.e. it's not the time zone of the Spreadsheet set via Spreadsheet Settings...)?
Now I'm in Italy so all locations are the same. When I calculate 2. from 1. it shows the right time only if the expense was made in the same Time Zone (Central Europe Time) because when I pick the date and add the time it gets written in the current time zone.
If I want to write the expense including the time zone manually set in the next column how can I do it?
Have I been able to set out the problem correctly?