What does Java's BST ZoneId represent?
Asked Answered
C

1

6

I have stored in the DB this Time Frame: any day from 15:00 to 16:00 in LONDON (BST)

I need to execute a program IF when I receive an event is between this Time Frame.

I am running the Test now in Paris (16:22) where in London is 15:22 (so in between the Time Frame stored in the DB).

SO this is my code

// create Local Date Time from what I have stored in the DB

LocalDateTime dateTime1 = LocalDateTime.of(2017, Month.JUNE, 15, 15, 00);
LocalDateTime dateTime2 = LocalDateTime.of(2017, Month.JUNE, 15, 16, 00);

Instant now = Instant.now();

System.out.println (now.isAfter (dateTime1.atZone(ZoneId.of("BST", ZoneId.SHORT_IDS)).toInstant()));
System.out.println (now.isBefore(dateTime2.atZone(ZoneId.of("BST", ZoneId.SHORT_IDS)).toInstant()));

theoretically now (16:22 in PARIS / 15:22 in LONDON) is after dateTime1 in LONDON (15:00) and before dateTime2 (16:00) in LONDON

but I got that now is not before that dateTime2

Chevrotain answered 15/6, 2017 at 14:29 Comment(1)
Never use the 3-4 character abbreviations for time zones. Those are not real time zones, not standardized, and not even unique! Use true time zone names in the format continent/region such as Europe/London, Europe/Paris, Asia/Kolkata, Pacific/Auckland.Forefront
T
16

As indicated in the javadoc of ZonedId.SHORT_IDS, “BST” is not British Summer Time but Bangladesh Standard Time (Asia/Dhaka).

You can check the value with:

System.out.println(ZoneId.of("BST", ZoneId.SHORT_IDS));

So I suggest using full time zone names to avoid any confusion:

ZoneId london = ZoneId.of("Europe/London")
Thumbstall answered 15/6, 2017 at 14:34 Comment(4)
IMHO, why has Oracle not deprecated this SHORT_IDS? It is a pitfall for most people.Thrifty
BST is for Bangladesh Standard Time (used in Dhaka all year round).Unwell
@MenoHochschild, if you read that documentation with friendly eyes, it says that SHORT_IDS is only included for old code that uses the deprecated abbreviations, not for new code. You’ve got a point still.Unwell
And yet Date#toString() returns... BST!Guyot

© 2022 - 2024 — McMap. All rights reserved.