001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.q2.cli;
020
021import org.jpos.q2.CLICommand;
022import org.jpos.q2.CLIContext;
023
024import java.time.Instant;
025import java.time.ZoneId;
026import java.time.format.TextStyle;
027import java.time.zone.ZoneOffsetTransition;
028import java.time.zone.ZoneOffsetTransitionRule;
029import java.util.List;
030import java.util.Locale;
031
032/** CLI command that prints the JVM time zone and its upcoming DST transitions. */
033@SuppressWarnings("unused")
034public class TZCHECK implements CLICommand
035{
036    /** Default constructor; no instance state to initialise. */
037    public TZCHECK() {}
038    public void exec(CLIContext cli, String[] args) throws Exception
039    {
040        ZoneId zi = ZoneId.systemDefault();
041        Instant i = Instant.now();
042        cli.println(
043            "         Zone ID: " + zi + " (" + zi.getDisplayName(TextStyle.FULL, Locale.getDefault()) + ") "
044                + zi.getRules().getOffset(i)
045        );
046        cli.println ("             UTC: " + i);
047        ZoneOffsetTransition tran = zi.getRules().nextTransition(i);
048        if (tran != null) {
049            Instant in = tran.getInstant();
050            cli.println (" Next transition: " + in + " (" + in.atZone(zi) + ")");
051        }
052        List<ZoneOffsetTransitionRule> l = zi.getRules().getTransitionRules();
053        for (ZoneOffsetTransitionRule r : l) {
054            cli.println (" Transition rule: " + r);
055        }
056    }
057}