Java LocalDateTime Calculate WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime)

Here you can find the source of WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime)

Description

Wizz Air Datetime Correction

License

Apache License

Declaration

public static LocalDateTime WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.time.*;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static LocalDateTime WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime) {
        // TODO: why must I add 1 more hour to get the right time?

        ZonedDateTime lZDT = aLocalDateTime.atZone(ZoneId.of("Europe/Budapest"));
        ZoneOffset lZO = lZDT.getOffset();
        String lZId = lZO.getId();

        Pattern reg = Pattern.compile("(\\+|-)(\\d{2})\\:(\\d{2})");
        Matcher m = reg.matcher(lZId);

        if (m.find()) {
            String lPrefix = m.group(1).toString().trim();
            String lHours = m.group(2).toString().trim();
            String lMinutes = m.group(3).toString().trim();

            if (lHours.charAt(0) == '0')
                lHours = lHours.substring(1);
            int lIHours = Integer.parseInt(lHours);
            if (lMinutes.charAt(0) == '0')
                lMinutes = lMinutes.substring(1);
            int lIMinutes = Integer.parseInt(lMinutes);

            if (lPrefix.equals("+")) {
                aLocalDateTime = aLocalDateTime.plusHours(lIHours - 1);
                aLocalDateTime = aLocalDateTime.plusMinutes(lIMinutes);
            } else {
                aLocalDateTime = aLocalDateTime.minusHours(lIHours - 1);
                aLocalDateTime = aLocalDateTime.minusMinutes(lIMinutes);
            }//from  w  ww  .  j a va  2 s  . c o m
        }

        return aLocalDateTime;
    }
}

Related

  1. shiftDateTime(String timex, LocalDateTime reference, boolean future)
  2. shouldSend(Optional emailSentOpt, int timeToWait)
  3. sleepUntil(LocalDateTime next)
  4. toCalendar(final LocalDateTime localDateTime)
  5. toOffsetDateTime(Date localDateTime, TimeZone clientTimeZone)