code: @SuppressWarnings("checkstyle:magicnumber")
      private static long toPgSecs(final long seconds) {
          long secs = seconds;
          // java epoc to postgres epoc
          secs -= 946684800L;
  
          // Julian/Greagorian calendar cutoff point
          if (secs < -13165977600L) { // October 15, 1582 -> October 4, 1582
              secs -= 86400 * 10;
              if (secs < -15773356800L) { // 1500-03-01 -> 1500-02-28
                  int years = (int) ((secs + 15773356800L) / -3155823050L);
                  years++;
                  years -= years / 4;
                  secs += years * 86400;
              }
          }
  
          return secs;
      }
docs: Converts the given java seconds to postgresql seconds. The conversion is valid for any year 100 BC onwards.
  
  from /org/postgresql/jdbc2/TimestampUtils.java
  
  @param seconds Postgresql seconds.
  @return Java seconds.