Java Java String Format toJavaSecs(long secs)

Here you can find the source of toJavaSecs(long secs)

Description

Converts the given postgresql seconds to java seconds.

License

Open Source License

Parameter

Parameter Description
secs Postgresql seconds.

Return

Java seconds.

Declaration

private static long toJavaSecs(long secs) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  ww.  j  a va 2s.  c  om*/
     * Converts the given postgresql seconds to java seconds.
     * Reverse engineered by inserting varying dates to postgresql
     * and tuning the formula until the java dates matched.
     *
     * @param secs Postgresql seconds.
     * @return Java seconds.
     */
    private static long toJavaSecs(long secs) {
        // postgres epoc to java epoc
        secs += 946684800L;

        // Julian/Gregorian calendar cutoff point
        if (secs < -12219292800L) { // October 4, 1582 -> October 15, 1582
            secs += 86400 * 10;
            if (secs < -14825808000L) { // 1500-02-28 -> 1500-03-01
                int extraLeaps = (int) ((secs + 14825808000L) / 3155760000L);
                extraLeaps--;
                extraLeaps -= extraLeaps / 4;
                secs += extraLeaps * 86400L;
            }
        }
        return secs;
    }
}

Related

  1. toJavaPath(String path)
  2. toJavaPattern(String pattern)
  3. toJavascriptArray(String[][] Vals)
  4. toJavaScriptEncode(String string)
  5. toJavaScriptSafeString(String content)
  6. toJavaSourceType(String type)
  7. toJavaStaticIdentifier(String string)
  8. toJavaString(final String s)
  9. toJavaString(String buf)