/*
 * Decompiled with CFR 0.152.
 */
package com.l7tech.server.wsdm.util;

import java.io.IOException;
import java.text.ParseException;
import java.util.Calendar;
import java.util.StringTokenizer;

public class ISO8601Duration {
    private int a;
    private double b;
    private double c;
    private double d;
    private double e;
    private double f;
    private double g;
    private static final String[] h;

    /*
     * Loose catch block
     */
    public ISO8601Duration(String string) throws ParseException {
        boolean bl2 = false;
        this.a = 1;
        this.b = -1.0;
        this.c = -1.0;
        this.d = -1.0;
        this.e = -1.0;
        this.f = -1.0;
        this.g = -1.0;
        String[] stringArray = h;
        StringTokenizer stringTokenizer = new StringTokenizer(string, stringArray[1], true);
        try {
            String string2 = stringTokenizer.nextToken();
            if (string2.equals("-")) {
                this.a = -1;
                string2 = stringTokenizer.nextToken();
            }
            try {
                if (!string2.equals("P")) {
                    throw new ParseException(string + h[4] + string2 + h[0], 0);
                }
            }
            catch (NumberFormatException numberFormatException) {
                throw ISO8601Duration.a(numberFormatException);
            }
            while (stringTokenizer.hasMoreTokens()) {
                String string3;
                block35: {
                    block34: {
                        block32: {
                            block33: {
                                string2 = stringTokenizer.nextToken();
                                if (!string2.equals("T")) break block32;
                                try {
                                    block36: {
                                        if (stringTokenizer.hasMoreTokens()) break block33;
                                        break block36;
                                        catch (NumberFormatException numberFormatException) {
                                            throw ISO8601Duration.a(numberFormatException);
                                        }
                                    }
                                    throw new ParseException(string + h[11] + string2 + h[6], 0);
                                }
                                catch (NumberFormatException numberFormatException) {
                                    throw ISO8601Duration.a(numberFormatException);
                                }
                            }
                            string2 = stringTokenizer.nextToken();
                            bl2 = true;
                        }
                        try {
                            if (!stringTokenizer.hasMoreTokens()) {
                                throw new ParseException(string + h[11] + string2 + h[8], 0);
                            }
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw ISO8601Duration.a(numberFormatException);
                        }
                        string3 = stringTokenizer.nextToken();
                        try {
                            if (string3.equals("Y")) {
                                this.b = Double.parseDouble(string2);
                                continue;
                            }
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw ISO8601Duration.a(numberFormatException);
                        }
                        if (!string3.equals("M")) break block34;
                        try {
                            block37: {
                                if (bl2) break block34;
                                break block37;
                                catch (NumberFormatException numberFormatException) {
                                    throw ISO8601Duration.a(numberFormatException);
                                }
                            }
                            this.c = Double.parseDouble(string2);
                            if (this.c == (double)((int)this.c)) continue;
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw ISO8601Duration.a(numberFormatException);
                        }
                        stringArray = h;
                        throw new ParseException(stringArray[10], 0);
                    }
                    try {
                        if (string3.equals("D")) {
                            this.d = Double.parseDouble(string2);
                            continue;
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw ISO8601Duration.a(numberFormatException);
                    }
                    if (string3.equals("H")) {
                        this.e = Double.parseDouble(string2);
                        bl2 = true;
                        continue;
                    }
                    if (!string3.equals("M")) break block35;
                    try {
                        block38: {
                            if (!bl2) break block35;
                            break block38;
                            catch (NumberFormatException numberFormatException) {
                                throw ISO8601Duration.a(numberFormatException);
                            }
                        }
                        this.f = Double.parseDouble(string2);
                        continue;
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw ISO8601Duration.a(numberFormatException);
                    }
                }
                try {
                    if (string3.equals("S")) {
                        this.g = Double.parseDouble(string2);
                        continue;
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw ISO8601Duration.a(numberFormatException);
                }
                stringArray = h;
                throw new ParseException(string + stringArray[3] + string3 + "?", 0);
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw new ParseException("[" + numberFormatException.getMessage() + h[12], 0);
        }
    }

    public long inSeconds() {
        double d10 = 0.0;
        if (this.b > 0.0) {
            d10 += this.b * 365.254 * 3600.0 * 24.0;
        }
        if (this.c > 0.0) {
            d10 += this.c * 30.43 * 3600.0 * 24.0;
        }
        if (this.d > 0.0) {
            d10 += this.d * 3600.0 * 24.0;
        }
        if (this.e > 0.0) {
            d10 += this.e * 3600.0;
        }
        if (this.f > 0.0) {
            d10 += this.f * 60.0;
        }
        if (this.g > 0.0) {
            d10 += this.g;
        }
        return Double.valueOf(d10 * (double)this.a).longValue();
    }

    public static String durationFromSecs(long l2) {
        long l3;
        try {
            if (l2 <= 60L) {
                return h[9] + l2 + "S";
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw ISO8601Duration.a(numberFormatException);
        }
        if (l2 <= 3600L) {
            long l4;
            long l5 = l2 / 60L;
            long l6 = l4 = l2 % 60L;
            long l7 = l5;
            String[] stringArray = h;
            return stringArray[5] + l7 + "M" + l6 + "S";
        }
        if (l2 <= 86400L) {
            long l8;
            long l9 = l2 / 3600L;
            long l10 = l2 % 3600L;
            long l11 = l10 / 60L;
            long l12 = l8 = l10 % 60L;
            long l13 = l11;
            long l14 = l9;
            String[] stringArray = h;
            return stringArray[5] + l14 + "H" + l13 + "M" + l12 + "S";
        }
        long l15 = l2 / 86400L;
        long l16 = l2 % 86400L;
        long l17 = l16 / 3600L;
        long l18 = (l16 %= 3600L) / 60L;
        long l19 = l3 = l16 % 60L;
        long l20 = l18;
        long l21 = l17;
        long l22 = l15;
        return "P" + l22 + h[7] + l21 + "H" + l20 + "M" + l19 + "S";
    }

    public Calendar addTo(Calendar calendar) throws IOException {
        int n2;
        int n3;
        int n4;
        int n5;
        int n6;
        if (this.b > 0.0) {
            int n7 = (int)this.b;
            n6 = (int)(365.254 * (this.b - (double)n7));
            n5 = (int)(8766.096000000001 * (this.b - (double)n7 - (double)n6 / 365.254));
            n4 = (int)(525965.76 * (this.b - (double)n7 - (double)n6 / 365.254 - (double)n5 / 24.0 / 365.254));
            n3 = (int)(3.15579456E7 * (this.b - (double)n7 - (double)n6 / 365.254 - (double)n5 / 24.0 / 365.254 - (double)n4 / 60.0 / 24.0 / 365.254));
            n2 = (int)(3.15579456E10 * (this.b - (double)n7 - (double)n6 / 365.254 - (double)n5 / 24.0 / 365.254 - (double)n4 / 60.0 / 24.0 / 365.254 - (double)n3 / 60.0 / 60.0 / 24.0 / 365.254));
            calendar.add(1, this.a * n7);
            calendar.add(6, this.a * n6);
            calendar.add(10, this.a * n5);
            calendar.add(12, this.a * n4);
            calendar.add(13, this.a * n3);
            calendar.add(14, this.a * n2);
        }
        if (this.c > 0.0) {
            int n8 = (int)this.c;
            try {
                if (this.c != (double)n8) {
                    throw new IOException(h[2]);
                }
            }
            catch (IOException iOException) {
                throw ISO8601Duration.a(iOException);
            }
            calendar.add(2, this.a * n8);
        }
        if (this.d > 0.0) {
            n6 = (int)this.d;
            n5 = (int)(24.0 * (this.d - (double)n6));
            n4 = (int)(1440.0 * (this.d - (double)n6 - (double)n5 / 24.0));
            n3 = (int)(86400.0 * (this.d - (double)n6 - (double)n5 / 24.0 - (double)n4 / 24.0 / 60.0));
            n2 = (int)(8.64E7 * (this.d - (double)n6 - (double)n5 / 24.0 - (double)n4 / 60.0 / 24.0 - (double)n3 / 60.0 / 60.0 / 24.0));
            calendar.add(6, this.a * n6);
            calendar.add(10, this.a * n5);
            calendar.add(12, this.a * n4);
            calendar.add(13, this.a * n3);
            calendar.add(14, this.a * n2);
        }
        if (this.e > 0.0) {
            n5 = (int)this.e;
            n4 = (int)(60.0 * (this.e - (double)n5));
            n3 = (int)(3600.0 * (this.e - (double)n5 - (double)n4 / 60.0));
            n2 = (int)(3600000.0 * (this.e - (double)n5 - (double)n4 / 60.0 - (double)n3 / 60.0 / 60.0));
            calendar.add(10, this.a * n5);
            calendar.add(12, this.a * n4);
            calendar.add(13, this.a * n3);
            calendar.add(14, this.a * n2);
        }
        if (this.f > 0.0) {
            n4 = (int)this.f;
            n3 = (int)(60.0 * (this.f - (double)n4));
            n2 = (int)(60000.0 * (this.f - (double)n4 - (double)n3 / 60.0));
            calendar.add(12, this.a * n4);
            calendar.add(13, this.a * n3);
            calendar.add(14, this.a * n2);
        }
        if (this.g > 0.0) {
            n3 = (int)this.g;
            n2 = (int)(1000.0 * (this.g - (double)n3));
            calendar.add(13, this.a * n3);
            calendar.add(14, this.a * n2);
        }
        return calendar;
    }

    public String toString() {
        StringBuffer stringBuffer;
        block53: {
            block55: {
                block54: {
                    block50: {
                        block52: {
                            block51: {
                                block48: {
                                    block44: {
                                        block46: {
                                            block45: {
                                                block41: {
                                                    block43: {
                                                        block42: {
                                                            block38: {
                                                                block40: {
                                                                    block39: {
                                                                        stringBuffer = new StringBuffer();
                                                                        try {
                                                                            if (this.a == -1) {
                                                                                stringBuffer.append("-");
                                                                            }
                                                                        }
                                                                        catch (NumberFormatException numberFormatException) {
                                                                            throw ISO8601Duration.a(numberFormatException);
                                                                        }
                                                                        try {
                                                                            try {
                                                                                stringBuffer.append("P");
                                                                                if (!(this.b > 0.0)) break block38;
                                                                                if (this.b != (double)((int)this.b)) break block39;
                                                                            }
                                                                            catch (NumberFormatException numberFormatException) {
                                                                                throw ISO8601Duration.a(numberFormatException);
                                                                            }
                                                                            stringBuffer.append((int)this.b);
                                                                            break block40;
                                                                        }
                                                                        catch (NumberFormatException numberFormatException) {
                                                                            throw ISO8601Duration.a(numberFormatException);
                                                                        }
                                                                    }
                                                                    stringBuffer.append(this.b);
                                                                }
                                                                stringBuffer.append("Y");
                                                            }
                                                            try {
                                                                try {
                                                                    if (!(this.c > 0.0)) break block41;
                                                                    if (this.c != (double)((int)this.c)) break block42;
                                                                }
                                                                catch (NumberFormatException numberFormatException) {
                                                                    throw ISO8601Duration.a(numberFormatException);
                                                                }
                                                                stringBuffer.append((int)this.c);
                                                                break block43;
                                                            }
                                                            catch (NumberFormatException numberFormatException) {
                                                                throw ISO8601Duration.a(numberFormatException);
                                                            }
                                                        }
                                                        stringBuffer.append(this.c);
                                                    }
                                                    stringBuffer.append("M");
                                                }
                                                try {
                                                    try {
                                                        if (!(this.d > 0.0)) break block44;
                                                        if (this.d != (double)((int)this.d)) break block45;
                                                    }
                                                    catch (NumberFormatException numberFormatException) {
                                                        throw ISO8601Duration.a(numberFormatException);
                                                    }
                                                    stringBuffer.append((int)this.d);
                                                    break block46;
                                                }
                                                catch (NumberFormatException numberFormatException) {
                                                    throw ISO8601Duration.a(numberFormatException);
                                                }
                                            }
                                            stringBuffer.append(this.d);
                                        }
                                        stringBuffer.append("D");
                                    }
                                    try {
                                        block49: {
                                            try {
                                                try {
                                                    try {
                                                        block47: {
                                                            try {
                                                                try {
                                                                    if (this.b > 0.0 || this.c > 0.0) break block47;
                                                                }
                                                                catch (NumberFormatException numberFormatException) {
                                                                    throw ISO8601Duration.a(numberFormatException);
                                                                }
                                                                if (!(this.d > 0.0)) break block48;
                                                            }
                                                            catch (NumberFormatException numberFormatException) {
                                                                throw ISO8601Duration.a(numberFormatException);
                                                            }
                                                        }
                                                        if (this.e > 0.0) break block49;
                                                    }
                                                    catch (NumberFormatException numberFormatException) {
                                                        throw ISO8601Duration.a(numberFormatException);
                                                    }
                                                    if (this.f > 0.0) break block49;
                                                }
                                                catch (NumberFormatException numberFormatException) {
                                                    throw ISO8601Duration.a(numberFormatException);
                                                }
                                                if (!(this.g > 0.0)) break block48;
                                            }
                                            catch (NumberFormatException numberFormatException) {
                                                throw ISO8601Duration.a(numberFormatException);
                                            }
                                        }
                                        stringBuffer.append("T");
                                    }
                                    catch (NumberFormatException numberFormatException) {
                                        throw ISO8601Duration.a(numberFormatException);
                                    }
                                }
                                try {
                                    try {
                                        if (!(this.e > 0.0)) break block50;
                                        if (this.e != (double)((int)this.e)) break block51;
                                    }
                                    catch (NumberFormatException numberFormatException) {
                                        throw ISO8601Duration.a(numberFormatException);
                                    }
                                    stringBuffer.append((int)this.e);
                                    break block52;
                                }
                                catch (NumberFormatException numberFormatException) {
                                    throw ISO8601Duration.a(numberFormatException);
                                }
                            }
                            stringBuffer.append(this.e);
                        }
                        stringBuffer.append("H");
                    }
                    try {
                        try {
                            if (!(this.f > 0.0)) break block53;
                            if (this.f != (double)((int)this.f)) break block54;
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw ISO8601Duration.a(numberFormatException);
                        }
                        stringBuffer.append((int)this.f);
                        break block55;
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw ISO8601Duration.a(numberFormatException);
                    }
                }
                stringBuffer.append(this.f);
            }
            stringBuffer.append("M");
        }
        try {
            if (this.g > 0.0) {
                stringBuffer.append(this.g);
                stringBuffer.append("S");
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw ISO8601Duration.a(numberFormatException);
        }
        return stringBuffer.toString();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[13];
                var3_1 = 0;
                var2_2 = "m#v\u001b\u001fP\u0010m}3\u0019\u0019\u001d)#x\"\u001a\u0002P&\"kv\u0011\u0005\u0002!9p9\u001b\b`I\u000f84$\b\u001e\u001a\u000ex8\u001b\u001f\u0004`,}2U\u0014\u0015#$t7\u0019P\u001d/#m>\u0006Q\u001dw9!\u001d\u0011\u0004`)l$\u0014\u0004\u0019/#92\u0010\u001c\u0019-$m3\u0007P\u00193m\u0003m#v\u0002\u001dM&w98\u001aP\u0006!!l3\u0006P\u0011&9|$U\u0014\u00052,m?\u001a\u001eP\u0014m}3\u0019\u0019\u001d)9v$\u0002\tM\u001b\u0003vv\u0011\u0015\u001c) p8\u0014\u0004\u001f2m\u007f9\u0007P\u00145?x\"\u001c\u001f\u001e\u0002\u001dM\u001e\u000ex8\u001b\u001f\u0004`=k9\u0016\u0015\u00033m}3\u0016\u0019\u001d!!9;\u001a\u001e\u0004(>8";
                var4_3 = "m#v\u001b\u001fP\u0010m}3\u0019\u0019\u001d)#x\"\u001a\u0002P&\"kv\u0011\u0005\u0002!9p9\u001b\b`I\u000f84$\b\u001e\u001a\u000ex8\u001b\u001f\u0004`,}2U\u0014\u0015#$t7\u0019P\u001d/#m>\u0006Q\u001dw9!\u001d\u0011\u0004`)l$\u0014\u0004\u0019/#92\u0010\u001c\u0019-$m3\u0007P\u00193m\u0003m#v\u0002\u001dM&w98\u001aP\u0006!!l3\u0006P\u0011&9|$U\u0014\u00052,m?\u001a\u001eP\u0014m}3\u0019\u0019\u001d)9v$\u0002\tM\u001b\u0003vv\u0011\u0015\u001c) p8\u0014\u0004\u001f2m\u007f9\u0007P\u00145?x\"\u001c\u001f\u001e\u0002\u001dM\u001e\u000ex8\u001b\u001f\u0004`=k9\u0016\u0015\u00033m}3\u0016\u0019\u001d!!9;\u001a\u001e\u0004(>8".length();
                var1_4 = 32;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 26;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ISO8601Duration.a(v0, ISO8601Duration.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = ":t!\u000eGnhQ\u0007IxnnwCKNs";
                    var4_3 = ":t!\u000eGnhQ\u0007IxnnwCKNs".length();
                    var1_4 = 3;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 77;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ISO8601Duration.a(v0, ISO8601Duration.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ISO8601Duration.h = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x5A);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 87;
                    case 1 -> 3;
                    case 2 -> 76;
                    case 3 -> 111;
                    case 4 -> 106;
                    case 5 -> 106;
                    default -> 90;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

