0

I have some small scripting-code in painless (a Groovy dialect, which itself is based on Java) that parses some timestamps with a zone-id. However, when doing calculations that involve crossing over a daylight-saving-time-boundary, the timezone-id is changed.

Reproducible example:

def form=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss (zzz)")
in=ZonedDateTime.parse(input, form)
out_plusweek=in.plusHours(168).format(form)

For most inputs I work with the result is fine: 2019-08-27 11:05:00 (Europe/Amsterdam) gives 2019-09-03 11:05:00 (Europe/Amsterdam), identical for similar dates.

However, if I input 2019-03-29 11:05:00 (Europe/Amsterdam), the out-variable is set to 2019-04-05 12:05:00 (CEST).

The value itself is fine, but the timezone-designation is changed to CEST (Central European Summer Time). It's correct, but no longer parseable by the next step in my script, which needs an id like Europe/Amsterdam

So how can I get 2019-04-05 12:05:00 (Europe/Amsterdam)?

Emil Bode
  • 1,784
  • 8
  • 16
  • 1
    @Abra Yes, `VV` was what I needed, thanks! And you're right, it's not strictly java. It's painless (used by elasticsearch), which is a Groovy dialect as I understand it (I have no experience with Groovy itself). – Emil Bode Aug 27 '19 at 10:32
  • @Abra And if you care about it: I'll accept your answer if you make it into one – Emil Bode Aug 27 '19 at 10:38

1 Answers1

1

I suggest using a different format pattern for printing out the result. Try using VV instead of zzz.

According to the documentation lowercase z will give you the time zone name such as Pacific Standard Time or PST. For the time zone ID such as America/Los_Angeles you need uppercase V. And:

If the count of letters is two, then the time-zone ID is output. Any other count of letters throws IllegalArgumentException.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Abra
  • 19,142
  • 7
  • 29
  • 41