コード例 #1
1
ファイル: DateUtil.java プロジェクト: hostcc/hermes2
  public static Calendar UTC2Calendar(String dateTime) throws UtilitiesException {
    Matcher m = UTC_PATTERNER.matcher(dateTime);
    if (m.matches() && m.groupCount() == 9) {
      int parts[] = new int[8];
      int i;
      for (i = 0; i < 6; i++) parts[i] = Integer.parseInt(m.group(i + 1));

      String ms = m.group(i + 1);
      if (ms == null) {
        parts[i++] = 0;
      } else {
        if (ms.length() > 3) ms = ms.substring(0, 3);
        parts[i++] = Integer.parseInt(ms);
      }
      String tzStr = m.group(i + 1);
      TimeZone tz = null;
      if (tzStr == null || tzStr.equals("Z")) tz = TimeZone.getTimeZone("UTC");
      else tz = TimeZone.getTimeZone("GMT" + tzStr);
      Calendar c = Calendar.getInstance();
      c.clear();
      c.setTimeZone(tz);
      c.set(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]);
      c.add(14, parts[6]);
      return c;
    } else {
      throw new UtilitiesException("Unable to convert datetime to UTC format:" + dateTime);
    }
  }
コード例 #2
1
ファイル: TimezoneTest.java プロジェクト: dstipp/pgjdbc
  public TimezoneTest(String name) {
    super(name);

    TimeZone UTC = TimeZone.getTimeZone("UTC"); // +0000 always
    TimeZone GMT03 = TimeZone.getTimeZone("GMT+03"); // +0300 always
    TimeZone GMT05 = TimeZone.getTimeZone("GMT-05"); // -0500 always
    TimeZone GMT13 = TimeZone.getTimeZone("GMT+13"); // +1000 always

    cUTC = Calendar.getInstance(UTC);
    cGMT03 = Calendar.getInstance(GMT03);
    cGMT05 = Calendar.getInstance(GMT05);
    cGMT13 = Calendar.getInstance(GMT13);
  }
コード例 #3
1
ファイル: ThaiGov.java プロジェクト: FauxFaux/jdk9-jdk
  void dateTest() throws RuntimeException {
    Locale locTH = new Locale("th", "TH", "TH");
    TimeZone tz = TimeZone.getTimeZone("PST");

    Calendar calGregorian = Calendar.getInstance(tz, Locale.US);
    calGregorian.clear();
    calGregorian.set(2002, 4, 1, 8, 30);
    final Date date = calGregorian.getTime();
    Calendar cal = Calendar.getInstance(tz, locTH);
    cal.clear();
    cal.setTime(date);

    final String strExpected =
        "\u0E27\u0E31\u0E19\u0E1E\u0E38\u0E18\u0E17\u0E35\u0E48\u0020\u0E51\u0020\u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21\u0020\u0E1E\u002E\u0E28\u002E\u0020\u0E52\u0E55\u0E54\u0E55\u002C\u0020\u0E58\u0020\u0E19\u0E32\u0E2C\u0E34\u0E01\u0E32\u0020\u0E53\u0E50\u0020\u0E19\u0E32\u0E17\u0E35\u0020\u0E50\u0E50\u0020\u0E27\u0E34\u0E19\u0E32\u0E17\u0E35";
    Date value = cal.getTime();

    // th_TH_TH test
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locTH);
    df.setTimeZone(tz);
    String str = df.format(value);

    if (!strExpected.equals(str)) {
      throw new RuntimeException();
    }
  }
コード例 #4
1
 @InitBinder("systemNotificationForm")
 protected void initBinder(WebDataBinder binder) {
   binder.setValidator(systemNotificationValidator);
   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
   sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
   binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
   binder.registerCustomEditor(
       SystemNotificationType.class, new EnumEditor(SystemNotificationType.class));
   binder.registerCustomEditor(
       SystemNotificationSeverity.class, new EnumEditor(SystemNotificationSeverity.class));
   binder.registerCustomEditor(
       List.class,
       "types",
       new CustomCollectionEditor(List.class) {
         @Override
         protected Object convertElement(Object element) {
           SystemNotificationType type = null;
           if (element != null) {
             try {
               type = SystemNotificationType.valueOf((String) element);
             } catch (Exception ex) {
               log.error(
                   String.format(
                       "Error converting element to SystemNotificationType: %s", element),
                   ex);
             }
           }
           return type;
         }
       });
 }
コード例 #5
1
ファイル: ExportServlet.java プロジェクト: Bacaa14/Coursola
  @Override
  public void init() throws ServletException {
    // TODO Auto-generated method stub
    super.init();
    filePath = getServletContext().getRealPath("") + File.separator + "schedule.ics";
    try {
      ical.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
      ical.getProperties().add(Version.VERSION_2_0);
      ical.getProperties().add(CalScale.GREGORIAN);
    } catch (Exception e) {
      System.out.println("iCalendar failed to import");
    }
    registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    timezone = registry.getTimeZone("America/New_York");
    tz = timezone.getVTimeZone();

    try {
      // Register the driver.
      Class.forName("org.postgresql.Driver").newInstance();
    } catch (Exception e) {
      e.printStackTrace();
    }
    String url = "jdbc:postgresql://hopper.cs.wlu.edu/corsola";
    try {
      con = DriverManager.getConnection(url, "web", "");
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
コード例 #6
0
  /**
   * Takes a packed-stream InputStream, and writes to a JarOutputStream. Internally the entire
   * buffer must be read, it may be more efficient to read the packed-stream to a file and pass the
   * File object, in the alternate method described below.
   *
   * <p>Closes its input but not its output. (The output can accumulate more elements.)
   *
   * @param in an InputStream.
   * @param out a JarOutputStream.
   * @exception IOException if an error is encountered.
   */
  public void unpack(InputStream in0, JarOutputStream out) throws IOException {
    assert (Utils.currentInstance.get() == null);
    TimeZone tz = (_props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)) ? null : TimeZone.getDefault();

    try {
      Utils.currentInstance.set(this);
      if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
      final int verbose = _props.getInteger(Utils.DEBUG_VERBOSE);
      BufferedInputStream in = new BufferedInputStream(in0);
      if (Utils.isJarMagic(Utils.readMagic(in))) {
        if (verbose > 0) Utils.log.info("Copying unpacked JAR file...");
        Utils.copyJarFile(new JarInputStream(in), out);
      } else if (_props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
        (new DoUnpack()).run(in, out);
        in.close();
        Utils.markJarFile(out);
      } else {
        (new NativeUnpack(this)).run(in, out);
        in.close();
        Utils.markJarFile(out);
      }
    } finally {
      _nunp = null;
      Utils.currentInstance.set(null);
      if (tz != null) TimeZone.setDefault(tz);
    }
  }
コード例 #7
0
    DataContextImpl(OptiqConnectionImpl connection, List<Object> parameterValues) {
      this.queryProvider = connection;
      this.typeFactory = connection.getTypeFactory();
      this.rootSchema = connection.rootSchema;

      // Store the time at which the query started executing. The SQL
      // standard says that functions such as CURRENT_TIMESTAMP return the
      // same value throughout the query.
      final long time = System.currentTimeMillis();
      final TimeZone timeZone = connection.getTimeZone();
      final long localOffset = timeZone.getOffset(time);
      final long currentOffset = localOffset;

      ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder();
      builder
          .put("utcTimestamp", time)
          .put("currentTimestamp", time + currentOffset)
          .put("localTimestamp", time + localOffset)
          .put("timeZone", timeZone);
      for (Ord<Object> value : Ord.zip(parameterValues)) {
        Object e = value.e;
        if (e == null) {
          e = AvaticaParameter.DUMMY_VALUE;
        }
        builder.put("?" + value.i, e);
      }
      map = builder.build();
    }
コード例 #8
0
ファイル: DateField.java プロジェクト: hlship/tapx
        public int compare(TimeZone o1, TimeZone o2) {
          int result = o1.getRawOffset() - o2.getRawOffset();

          if (result == 0) result = o1.getDisplayName(locale).compareTo(o2.getDisplayName(locale));

          return result;
        }
コード例 #9
0
  public void testDateIssues() throws Exception {

    // test System.currentTimeMillis()
    long myApproximateTime = (long) 1.4412384e+12; // the current time of test execution
    long ct = System.currentTimeMillis();
    assertTrue(ct > myApproximateTime);

    // test date conversion and millisecond diffing
    DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yy");
    DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
    DateFormat DATE_FORMAT2 = new SimpleDateFormat("dd/MM/yy");
    DATE_FORMAT2.setTimeZone(TimeZone.getTimeZone("Europe/Rome"));

    Date d1 =
        DATE_FORMAT.parse(
            "13/09/15"); // the same date comes before in Europe than in America/Pacific
    Date d2 = DATE_FORMAT2.parse("13/09/15");

    assertTrue(d2.compareTo(d1) < 0);
    assertTrue(d2.getTime() < d1.getTime());

    long diff = d1.getTime() - d2.getTime();
    long hoursDiff = TimeUnit.HOURS.convert(diff, TimeUnit.MILLISECONDS);

    assertTrue(hoursDiff == 9L);

    // parse milliseconds, compare dates
    Date d3 = new Date(myApproximateTime);
    Date d4 = new Date(ct);

    assertTrue(d4.compareTo(d3) > 0);
  }
コード例 #10
0
ファイル: StringUtil.java プロジェクト: shadewly/zhaoshifu
 /**
  * Parse the given {@code timeZoneString} value into a {@link TimeZone}.
  *
  * @param timeZoneString the time zone String, following {@link TimeZone#getTimeZone(String)} but
  *     throwing {@link IllegalArgumentException} in case of an invalid time zone specification
  * @return a corresponding {@link TimeZone} instance
  * @throws IllegalArgumentException in case of an invalid time zone specification
  */
 public static TimeZone parseTimeZoneString(String timeZoneString) {
   TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
   if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
     // We don't want that GMT fallback...
     throw new IllegalArgumentException(
         "Invalid time zone specification '" + timeZoneString + "'");
   }
   return timeZone;
 }
コード例 #11
0
 public void test_toOffsetTime_variableOffset() {
   GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris"));
   gcal.set(2008, 0, 1, 0, 0, 0);
   gcal.set(Calendar.MILLISECOND, 0);
   for (int i = 0; i < 500; i++) {
     OffsetTime test = gcal.toOffsetTime();
     assertEquals(test.toLocalTime().toNanoOfDay(), 0);
     boolean isDST = TimeZone.getTimeZone("Europe/Paris").inDaylightTime(gcal.getTime());
     assertEquals(test.getOffset().getID(), isDST ? "+02:00" : "+01:00");
     gcal.add(Calendar.DATE, 1);
   }
 }
コード例 #12
0
ファイル: DateField.java プロジェクト: hlship/tapx
  /**
   * Converts a Date in default time zone to client's time zone.
   *
   * @param inputDate a date in the default time zone
   * @return a date in the client time zone
   */
  private Date convertDateToClientTimeZone(Date inputDate) {
    Calendar c = Calendar.getInstance(locale);
    c.setTime(inputDate);

    TimeZone clientZone = timeZoneTracker.getClientTimeZone();
    TimeZone defaultZone = TimeZone.getDefault();
    long now = System.currentTimeMillis();
    int offset = defaultZone.getOffset(now) - clientZone.getOffset(now);

    c.add(Calendar.MILLISECOND, offset);

    return c.getTime();
  }
コード例 #13
0
  void test1() {
    Locale[] available = Locale.getAvailableLocales();
    List<Locale> jreimplloc =
        Arrays.asList(
            LocaleProviderAdapter.forJRE().getTimeZoneNameProvider().getAvailableLocales());
    List<Locale> providerLocales = Arrays.asList(tznp.getAvailableLocales());
    String[] ids = TimeZone.getAvailableIDs();

    for (Locale target : available) {
      // pure JRE implementation
      OpenListResourceBundle rb =
          ((ResourceBundleBasedAdapter) LocaleProviderAdapter.forJRE())
              .getLocaleData()
              .getTimeZoneNames(target);
      boolean jreSupportsTarget = jreimplloc.contains(target);

      for (String id : ids) {
        // the time zone
        TimeZone tz = TimeZone.getTimeZone(id);

        // JRE string array for the id
        String[] jrearray = null;
        if (jreSupportsTarget) {
          try {
            jrearray = rb.getStringArray(id);
          } catch (MissingResourceException mre) {
          }
        }

        for (int i = 1; i <= (tz.useDaylightTime() ? 4 : 2); i++) {
          // the localized name
          String name = tz.getDisplayName(i >= 3, i % 2, target);

          // provider's name (if any)
          String providersname = null;
          if (providerLocales.contains(target)) {
            providersname = tznp.getDisplayName(id, i >= 3, i % 2, target);
          }

          // JRE's name
          String jresname = null;
          if (jrearray != null) {
            jresname = jrearray[i];
          }

          checkValidity(
              target, jresname, providersname, name, jreSupportsTarget && jresname != null);
        }
      }
    }
  }
コード例 #14
0
ファイル: RaidCommands.java プロジェクト: Whytemeet/nexusbot
 /** This code borrowed from Piesquared on irc.nexuswar.com */
 private TimeZone tZF(String search) {
   if (search.equals("")) return TimeZone.getTimeZone("GMT");
   search = search.toLowerCase();
   search = search.replace("+", "\\+");
   search = search.replace("*", "\\*");
   search = search.replace("?", "\\?");
   String[] zones = TimeZone.getAvailableIDs();
   for (int i = 0; i < zones.length; i++)
     if (zones[i].toLowerCase().equals(search)) return TimeZone.getTimeZone(zones[i]);
   for (int i = 0; i < zones.length; i++)
     if (zones[i].toLowerCase().matches(".*" + search + ".*"))
       return TimeZone.getTimeZone(zones[i]);
   return TimeZone.getTimeZone("GMT");
 }
コード例 #15
0
  void test2() {
    Locale defaultLocale = Locale.getDefault();
    TimeZone reservedTimeZone = TimeZone.getDefault();
    Date d = new Date(2005 - 1900, Calendar.DECEMBER, 22);
    String formatted;

    TimeZone tz;
    SimpleDateFormat df;

    try {
      for (int i = 0; i < TIMEZONES.length; i++) {
        tz = TimeZone.getTimeZone(TIMEZONES[i]);
        TimeZone.setDefault(tz);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(OSAKA));
        Locale.setDefault(defaultLocale);
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_OSAKA[i])) {
          throw new RuntimeException(
              "TimeZone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_OSAKA[i]);
        }

        df.parse(DISPLAY_NAMES_OSAKA[i]);

        Locale.setDefault(KYOTO);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
          throw new RuntimeException(
              "Timezone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_KYOTO[i]);
        }
        df.parse(DISPLAY_NAMES_KYOTO[i]);
      }
    } catch (ParseException pe) {
      throw new RuntimeException("parse error occured" + pe);
    } finally {
      // restore the reserved locale and time zone
      Locale.setDefault(defaultLocale);
      TimeZone.setDefault(reservedTimeZone);
    }
  }
コード例 #16
0
 private void setTimeZone(String line) throws JBookTraderException {
   String timeZone = line.substring(line.indexOf('=') + 1);
   TimeZone tz = TimeZone.getTimeZone(timeZone);
   if (!tz.getID().equals(timeZone)) {
     String msg =
         "The specified time zone " + "\"" + timeZone + "\"" + " does not exist." + LINE_SEP;
     msg += "Examples of valid time zones: " + " America/New_York, Europe/London, Asia/Singapore.";
     throw new JBookTraderException(msg);
   }
   sdf = new SimpleDateFormat("MMddyyHHmmss");
   // Enforce strict interpretation of date and time formats
   sdf.setLenient(false);
   sdf.setTimeZone(tz);
 }
コード例 #17
0
 public void test_toOffsetDate_variableOffset() {
   GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris"));
   gcal.set(2008, 0, 1, 0, 0, 0);
   gcal.set(Calendar.MILLISECOND, 0);
   for (int i = 0; i < 500; i++) {
     OffsetDate test = gcal.toOffsetDate();
     assertEquals(test.getYear(), gcal.get(Calendar.YEAR));
     assertEquals(test.getMonthOfYear().getValue(), gcal.get(Calendar.MONTH) + 1);
     assertEquals(test.getDayOfMonth(), gcal.get(Calendar.DATE));
     assertEquals(test.getYear(), i < 366 ? 2008 : 2009);
     boolean isDST = TimeZone.getTimeZone("Europe/Paris").inDaylightTime(gcal.getTime());
     assertEquals(test.getOffset().getID(), isDST ? "+02:00" : "+01:00");
     gcal.add(Calendar.DATE, 1);
   }
 }
コード例 #18
0
ファイル: CalendarImpl.java プロジェクト: sherckuith/jop
  /**
   * Converts this <code>Date</code> object to a <code>String</code>. The output format is as
   * follows:
   *
   * <blockquote>
   *
   * <pre>yyyy MM dd hh mm ss +zzzz</pre>
   *
   * </blockquote>
   *
   * where:
   *
   * <ul>
   *   <li>
   *   <dd>yyyy is the year, as four decimal digits. Year values larger than
   *   <dd>9999 will be truncated to
   *   <dd>9999.
   *   <li>
   *   <dd>MM is the month (
   *   <dd>01 through
   *   <dd>12), as two decimal digits.
   *   <li>
   *   <dd>dd is the day of the month (
   *   <dd>01 through
   *   <dd>31), as two decimal digits.
   *   <li>
   *   <dd>hh is the hour of the day (
   *   <dd>00 through
   *   <dd>23), as two decimal digits.
   *   <li>
   *   <dd>mm is the minute within the hour (
   *   <dd>00 through
   *   <dd>59), as two decimal digits.
   *   <li>
   *   <dd>ss is the second within the minute (
   *   <dd>00 through
   *   <dd>59), as two decimal digits.
   *   <li>
   *   <dd>zzzz is the time zone offset in hours and minutes (four decimal digits
   *   <dd>"hhmm") relative to GMT, preceded by a "+" or "-" character (
   *   <dd>-1200 through
   *   <dd>+1200). For instance, Pacific Standard Time zone is printed as
   *   <dd>-0800. GMT is printed as
   *   <dd>+0000.
   * </ul>
   *
   * @return a string representation of this date.
   */
  public static String toISO8601String(Calendar calendar) {
    // Printing in the absence of a Calendar
    // implementation class is not supported
    if (calendar == null) {
      return "0000 00 00 00 00 00 +0000";
    }

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1;
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int hour_of_day = calendar.get(Calendar.HOUR_OF_DAY);
    int hour = calendar.get(Calendar.HOUR);
    int minute = calendar.get(Calendar.MINUTE);
    int seconds = calendar.get(Calendar.SECOND);

    String yr = Integer.toString(year);

    // The total size of the string buffer
    // yr.length+1+2+1+2+1+2+1+2+1+2+1+5 = 25 + yr.length
    StringBuffer sb = new StringBuffer(25 + yr.length());

    appendFourDigits(sb, year).append(' ');
    appendTwoDigits(sb, month).append(' ');
    appendTwoDigits(sb, day).append(' ');
    appendTwoDigits(sb, hour_of_day).append(' ');
    appendTwoDigits(sb, minute).append(' ');
    appendTwoDigits(sb, seconds).append(' ');

    // TimeZone offset is represented in milliseconds.
    // Convert the offset to minutes:
    TimeZone t = calendar.getTimeZone();
    int zoneOffsetInMinutes = t.getRawOffset() / 1000 / 60;

    if (zoneOffsetInMinutes < 0) {
      zoneOffsetInMinutes = Math.abs(zoneOffsetInMinutes);
      sb.append('-');
    } else {
      sb.append('+');
    }

    int zoneHours = zoneOffsetInMinutes / 60;
    int zoneMinutes = zoneOffsetInMinutes % 60;

    appendTwoDigits(sb, zoneHours);
    appendTwoDigits(sb, zoneMinutes);

    return sb.toString();
  }
コード例 #19
0
  /** Returns the time zone for which this <code>CronExpression</code> will be resolved. */
  public TimeZone getTimeZone() {
    if (timeZone == null) {
      timeZone = TimeZone.getDefault();
    }

    return timeZone;
  }
コード例 #20
0
  /**
   * Creates the Hadoop authentication HTTP cookie.
   *
   * @param token authentication token for the cookie.
   * @param expires UNIX timestamp that indicates the expire date of the cookie. It has no effect if
   *     its value < 0.
   *     <p>XXX the following code duplicate some logic in Jetty / Servlet API, because of the fact
   *     that Hadoop is stuck at servlet 2.5 and jetty 6 right now.
   */
  public static void createAuthCookie(
      HttpServletResponse resp,
      String token,
      String domain,
      String path,
      long expires,
      boolean isSecure) {
    StringBuilder sb = new StringBuilder(AuthenticatedURL.AUTH_COOKIE).append("=");
    if (token != null && token.length() > 0) {
      sb.append("\"").append(token).append("\"");
    }
    sb.append("; Version=1");

    if (path != null) {
      sb.append("; Path=").append(path);
    }

    if (domain != null) {
      sb.append("; Domain=").append(domain);
    }

    if (expires >= 0) {
      Date date = new Date(expires);
      SimpleDateFormat df = new SimpleDateFormat("EEE, " + "dd-MMM-yyyy HH:mm:ss zzz");
      df.setTimeZone(TimeZone.getTimeZone("GMT"));
      sb.append("; Expires=").append(df.format(date));
    }

    if (isSecure) {
      sb.append("; Secure");
    }

    sb.append("; HttpOnly");
    resp.addHeader("Set-Cookie", sb.toString());
  }
コード例 #21
0
ファイル: TimezoneTest.java プロジェクト: dstipp/pgjdbc
  protected void tearDown() throws Exception {
    // System.err.println("++++++ TESTS END (" + getName() + ") ++++++");
    TimeZone.setDefault(saveTZ);

    TestUtil.dropTable(con, "testtimezone");
    TestUtil.closeDB(con);
  }
コード例 #22
0
 private void finalizePartitionsUpTo(String topic, Calendar calendar)
     throws IOException, ParseException, InterruptedException {
   NavigableSet<Calendar> partitionDates =
       getPartitions(topic).headSet(calendar, true).descendingSet();
   final String s3Prefix = "s3n://" + mConfig.getS3Bucket() + "/" + mConfig.getS3Path();
   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
   format.setTimeZone(TimeZone.getTimeZone("UTC"));
   for (Calendar partition : partitionDates) {
     String partitionStr = format.format(partition.getTime());
     String[] partitions = {"dt=" + partitionStr};
     LogFilePath logFilePath =
         new LogFilePath(
             s3Prefix, topic, partitions, mConfig.getGeneration(), 0, 0, mFileExtension);
     String logFileDir = logFilePath.getLogFileDir();
     assert FileUtil.exists(logFileDir) : "FileUtil.exists(" + logFileDir + ")";
     String successFilePath = logFileDir + "/_SUCCESS";
     if (FileUtil.exists(successFilePath)) {
       return;
     }
     try {
       mQuboleClient.addPartition(mConfig.getHivePrefix() + topic, "dt='" + partitionStr + "'");
     } catch (Exception e) {
       LOG.error("failed to finalize topic " + topic + " partition dt=" + partitionStr, e);
       continue;
     }
     LOG.info("touching file " + successFilePath);
     FileUtil.touch(successFilePath);
   }
 }
コード例 #23
0
  public static Collection<BatchPoints> create(
      int chunksize, String db, ZeitreihenDTO... zeitreihenDTOs) throws ParseException {
    List<Point> points = new ArrayList<>();
    for (ZeitreihenDTO zeitreihenDTO : zeitreihenDTOs) {
      for (Long timestamp : timestamps(zeitreihenDTO)) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        calendar.setTimeInMillis(timestamp);
        int monat = calendar.get(Calendar.MONTH) + 1;
        int jahr = calendar.get(Calendar.YEAR);

        points.add(
            Point.measurement("lastgang")
                .tag("zaehlpunktbezeichnung", zeitreihenDTO.zaehlpunktbezeichnung)
                .tag("commodity", zeitreihenDTO.commodity)
                .tag("zaehlverfahren", zeitreihenDTO.zaehlverfahren)
                .tag("monat", String.valueOf(monat))
                .tag("jahr", String.valueOf(jahr))
                .time(timestamp, TimeUnit.MILLISECONDS)
                .field("value", randomValue())
                .build());
      }
    }

    Collection<BatchPoints> batchPoints = new ArrayList<>();
    Lists.partition(points, chunksize)
        .forEach(
            chunk -> {
              BatchPoints bp = BatchPoints.database(db).retentionPolicy("default").build();

              chunk.forEach(bp::point);
              batchPoints.add(bp);
            });
    return batchPoints;
  }
コード例 #24
0
  public static BatchPoints create(String db, ZeitreihenDTO... zeitreihenDTOs)
      throws ParseException {
    BatchPoints batchPoints = BatchPoints.database(db).retentionPolicy("default").build();

    for (ZeitreihenDTO zeitreihenDTO : zeitreihenDTOs) {
      for (Long timestamp : timestamps(zeitreihenDTO)) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        calendar.setTimeInMillis(timestamp);
        int monat = calendar.get(Calendar.MONTH) + 1;
        int jahr = calendar.get(Calendar.YEAR);

        batchPoints.point(
            Point.measurement("lastgang")
                .tag("zaehlpunktbezeichnung", zeitreihenDTO.zaehlpunktbezeichnung)
                .tag("commodity", zeitreihenDTO.commodity)
                .tag("zaehlverfahren", zeitreihenDTO.zaehlverfahren)
                .tag("monat", String.valueOf(monat))
                .tag("jahr", String.valueOf(jahr))
                .time(timestamp, TimeUnit.MILLISECONDS)
                .field("value", randomValue())
                .build());
      }
    }
    return batchPoints;
  }
コード例 #25
0
ファイル: DateUtil.java プロジェクト: hostcc/hermes2
 public static String date2UTC(Date dateTime, TimeZone timeZone) throws UtilitiesException {
   try {
     DecimalFormat twoDigits;
     String utc;
     String sign;
     int hours;
     int minutes;
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
     dateFormatter.setLenient(false);
     dateFormatter.setTimeZone(timeZone);
     twoDigits = new DecimalFormat("00");
     utc = dateFormatter.format(dateTime);
     int tzOffset = timeZone.getOffset(dateTime.getTime());
     sign = "+";
     if (tzOffset < 0) {
       sign = "-";
       tzOffset = -tzOffset;
     }
     hours = tzOffset / 0x36ee80;
     minutes = (tzOffset % 0x36ee80) / 60000;
     return (new StringBuffer(utc.length() + 7))
         .append(utc)
         .append(sign)
         .append(twoDigits.format(hours))
         .append(":")
         .append(twoDigits.format(minutes))
         .toString();
   } catch (Exception ex) {
     throw new hk.hku.cecid.piazza.commons.util.UtilitiesException(ex);
   }
 }
コード例 #26
0
ファイル: DateUtil.java プロジェクト: hostcc/hermes2
 public static String getCurrentUTCDateTime() {
   try {
     return date2UTC(new Date(), TimeZone.getDefault());
   } catch (UtilitiesException ex) {
     return null;
   }
 }
コード例 #27
0
 @Override
 public String toString(long timestamp, String timezone) {
   // Por enquanto, o fuso horário deve ser UTC:
   assert timezone.equals("UTC");
   DateFormat formatter = new SimpleDateFormat(DEFAULT_FORMAT);
   formatter.setTimeZone(TimeZone.getTimeZone(timezone));
   return formatter.format(new Date(timestamp * 1000)) + " " + timezone;
 }
コード例 #28
0
 @Override
 public void setUp() {
   Calendar cal = new GregorianCalendar(2007, 8 - 1, 13, 19, 51, 23);
   cal.setTimeZone(TimeZone.getTimeZone("GMT"));
   cal.set(Calendar.MILLISECOND, 0);
   date = cal.getTime();
   df = new ISO8601DateFormat();
 }
コード例 #29
0
ファイル: JdbcUtils.java プロジェクト: new-emacs/optiq
 private static Date shift(Date v) {
   if (v == null) {
     return null;
   }
   long time = v.getTime();
   int offset = TimeZone.getDefault().getOffset(time);
   return new Date(time + offset);
 }
コード例 #30
0
ファイル: JdbcUtils.java プロジェクト: new-emacs/optiq
 private static Time shift(Time v) {
   if (v == null) {
     return null;
   }
   long time = v.getTime();
   int offset = TimeZone.getDefault().getOffset(time);
   return new Time((time + offset) % DateTimeUtil.MILLIS_PER_DAY);
 }