Can apoc.date.parse accept timezone name rather than offset? - neo4j-apoc

Can apoc.date.parse accept timezone name such as 'America/Los_Angeles' rather than offset such as '-0800'? If not, is there any other way to do it?

Related

JS - Convert a "Europe/Berlin"-Date into a UTC-Timestamp

Inside my Docker-Container, which has the timezone Etc/UTC, I need to convert a Date-String which represents a Date in Europe/Berlin-timezone into a UTC timestamp.
So lets say the Europe/Berlin-Date is 2022-04-20T00:00:00.
Now the UTC-Timestamp should be equivalent to 2022-04-19T22:00:00.
But when I do
console.log(new Date("2022-04-20").getTime())
I get 1650412800000 which is equivalent to 2022-04-20T02:00:00 in Europe/Berlin-timezone.
How would I do this?
Edit:
I tried various libs, but still cant get that managed
const { DateTime } = require("luxon")
var f = DateTime.fromISO("2022-04-20").setZone('Europe/Berlin').toUTC()
console.log(f)
also the equivalent stamp in f is 2022-04-20T02:00:00 :/
I need to convert a Date-String which represents a Date in Europe/Berlin-timezone into a UTC timestamp.
Fundamentally, a date-only value cannot be converted into a timestamp, unless you arbitrarily associate a time with that date. It sounds like you meant to use midnight local time (00:00+02:00) but instead you are seeing midnight UTC (00:00Z).
This is due to how you are constructing the Date object. You specify new Date("2022-04-20"), which according to the ECMASCript spec will be treated as midnight UTC. The spec says:
... When the UTC offset representation is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time.
Yes, this is inconsistent with ISO 8601, and that has been discussed ad nauseum.
To solve this problem, append T00:00 to your input string, so that you are specifically asking for local time. In other words, new Date("2022-04-20T00:00").
That said, if you need it to not be "local time" but exactly Europe/Berlin, then yes - you'll need to use a library. In luxon, it's like this:
DateTime.fromISO('2022-04-20T00:00', {zone: 'Europe/Berlin'}).toUTC()

Timex - Getting the timezone information from DateTime

I am looking for a way to get the timezone information back from a date time.
iex(13)> t = Timex.now("America/Los_Angeles")
#<DateTime(2016-10-23T12:45:34.697369-07:00 America/Los_Angeles)>
iex(14)> Timex.<given_t_return_timezone>??
Given t, I want back "America/Los_Angeles" again.
I knew it had to be easy. Rather than looking at Timex for this, we can simply do:
t.time_zone
This is part of Elixir itself since t is a DateTime.

Node's Postgres module pg returns wrong date

I have declared a date column in Postgres as date.
When I write the value with node's pg module, the Postgres Tool pgAdmin displays it correctly.
When I read the value back using pg, Instead of plain date, a date-time string comes with wrong day.
e.g.:
Date inserted: 1975-05-11
Date displayed by pgAdmin: 1975-05-11
Date returned by node's pg: 1975-05-10T23:00:00.000Z
Can I prevent node's pg to appy time-zone to date-only data? It is intended for day of birth and ihmo time-zone has no relevance here.
EDIT Issue response from Developer on github
The node-postgres team decided long ago to convert dates and datetimes
without timezones to local time when pulling them out. This is consistent
with some documentation we've dug up in the past. If you root around
through old issues here you'll find the discussions.
The good news is its trivially easy to over-ride this behavior and return
dates however you see fit.
There's documentation on how to do this here:
https://github.com/brianc/node-pg-types
There's probably even a module somewhere that will convert dates from
postgres into whatever timezone you want (utc I'm guessing). And if
there's not...that's a good opportunity to write one & share with everyone!
Original message
Looks like this is an issue in pg-module.
I'm a beginner in JS and node, so this is only my interpretation.
When dates (without time-part) are parsed, local time is assumed.
pg\node_modules\pg-types\lib\textParsers.js
if(!match) {
dateMatcher = /^(\d{1,})-(\d{2})-(\d{2})$/;
match = dateMatcher.test(isoDate);
if(!match) {
return null;
} else {
//it is a date in YYYY-MM-DD format
//add time portion to force js to parse as local time
return new Date(isoDate + ' 00:00:00');
But when the JS date object is converted back to a string getTimezoneOffset is applied.
pg\lib\utils.js s. function dateToString(date)
Another option is change the data type of the column:
You can do this by running the command:
ALTER TABLE table_name
ALTER COLUMN column_name_1 [SET DATA] TYPE new_data_type,
ALTER COLUMN column_name_2 [SET DATA] TYPE new_data_type,
...;
as descripted here.
I'd the same issue, I changed to text.
Just override node-postgres parser for the type date (1082) and return the value without parsing it:
import pg from pg
pg.types.setTypeParser(1082, value => value)

Inverted zone in moment.timezone

I am using nodejs and recently started using moment.timezone to get the timezone offset. I have the following code:
console.log(moment.tz(new Date(), 'Europe/Athens').zone()); // Prints -120
The timezone for 'Europe/Athens' is GMT+2 so i would expect getting '120' and not '-120' and thats what other timezone libraries do.
This issue caused me a serious head scratching bug. It was really easy to fix it once found the problem by just inverting the timezone offset.
Is this a bug on the specific library, or is there a different way to think of zones and offsets? Is there a standard about zone offsets?
This is expected behavior. zone() returns the offset to UTC relative to the selected timezone.
http://momentjs.com/timezone/docs/#/how-to/mutator/

Timezone format connections

I got the time values from the SBT SDK as a string in this format
"2013-07-17T14:44:25.177Z"
I get a Java Date object with this code
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = dateFormat.parse("2013-07-17T14:44:25.177Z");
But the last part of the string ".177Z" should be a time zone value !?!?!
Do any body know how parse the time zone or the complete date with the time zone in Java?
Thx
Andreas
But the last part of the string ".177Z" should be a time zone value !?!?!
No, I think the .177 is the milliseconds part, and Z is a UTC-offset of 0. (It's not really a time zone, but that's a different matter.)
I suspect you want:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
(Where X is an ISO-8601 time zone specifier, including Z for UTC.)
Note that X was only introduced in Java 7 - if you're using Java 6 or earlier, you may need to do a bit more work.
You might want to use
javax.xml.bind.DatatypeConverter.parseTime(String)
since the dates found in the atom returned by the IBM Connections API conform to the definition from http://www.w3.org/TR/xmlschema-2/, which can be parsed into a Java Calendar Object by said method. This also accounts for the time zone specifier.

Resources