The issue with the code is that you are formatting the time using the toFormat method, but you are not actually converting the dateTimeObject to the 'Europe/Lisbon' time zone.
To fix this, you need to chain the setZone method before formatting the time. Here's the corrected code:
DateTime.fromSeconds(item.scheduled_arrival_unix, { zone: 'UTC' }) creates a DateTime object from the Unix timestamp, assuming it represents a UTC time.
setZone('Europe/Lisbon') converts the DateTime object to the 'Europe/Lisbon' time zone.
toFormat('HH:mm') formats the time in the 'HH:mm' format (hours and minutes).
By chaining setZone before toFormat, you ensure that the time is converted to the desired time zone before formatting it.
Also, note that you don't need to specify the time zone in the toFormat method since you have already set the time zone using setZone. The toFormat('HH:mm') will format the time according to the time zone set by setZone.
With these changes, the code should correctly return the time in the 'Europe/Lisbon' time zone.
https://github.com/carrismetropolitana/website/blob/4686b1056bfef56e2ad3f3a00f31acf3da8cbfa0/nextjs/components/FrontendLinesContentPatternPathStopRealtime/FrontendLinesContentPatternPathStopRealtime.js#L89
The issue with the code is that you are formatting the time using the
toFormat
method, but you are not actually converting thedateTimeObject
to the 'Europe/Lisbon' time zone.To fix this, you need to chain the
setZone
method before formatting the time. Here's the corrected code:Explanation:
DateTime.fromSeconds(item.scheduled_arrival_unix, { zone: 'UTC' })
creates aDateTime
object from the Unix timestamp, assuming it represents a UTC time.setZone('Europe/Lisbon')
converts theDateTime
object to the 'Europe/Lisbon' time zone.toFormat('HH:mm')
formats the time in the 'HH:mm' format (hours and minutes).By chaining
setZone
beforetoFormat
, you ensure that the time is converted to the desired time zone before formatting it.Also, note that you don't need to specify the time zone in the
toFormat
method since you have already set the time zone usingsetZone
. ThetoFormat('HH:mm')
will format the time according to the time zone set bysetZone
.With these changes, the code should correctly return the time in the 'Europe/Lisbon' time zone.