コード例 #1
1
ファイル: Util.java プロジェクト: ptrvif/openhab
  public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone(timeZone.getID());

    Calendar calendar = new Calendar();
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(new ProdId("openHAB"));
    VEvent vEvent = new VEvent();
    vEvent.getProperties().add(new Summary(calDavEvent.getName()));
    vEvent.getProperties().add(new Description(calDavEvent.getContent()));
    final DtStart dtStart =
        new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
    dtStart.setTimeZone(timezone);
    vEvent.getProperties().add(dtStart);
    final DtEnd dtEnd =
        new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
    dtEnd.setTimeZone(timezone);
    vEvent.getProperties().add(dtEnd);
    vEvent.getProperties().add(new Uid(calDavEvent.getId()));
    vEvent.getProperties().add(Clazz.PUBLIC);
    vEvent
        .getProperties()
        .add(
            new LastModified(
                new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
    calendar.getComponents().add(vEvent);

    return calendar;
  }
コード例 #2
0
  @Override
  public void updateAnnotation(
      final UUID annotationId,
      final String annotationText,
      final String client,
      final long time,
      final DateTimeZone timezone)
      throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Updating an annotation.");

    try {
      // Begin the transaction.
      PlatformTransactionManager transactionManager =
          new DataSourceTransactionManager(getDataSource());
      TransactionStatus status = transactionManager.getTransaction(def);

      try {
        getJdbcTemplate()
            .update(
                SQL_UPDATE_ANNOTATION,
                time,
                timezone.getID(),
                client,
                annotationText,
                annotationId.toString());
      } catch (org.springframework.dao.DataAccessException e) {

        transactionManager.rollback(status);
        throw new DataAccessException(
            "Error executing SQL '"
                + SQL_UPDATE_ANNOTATION
                + "' with parameters: "
                + time
                + ", "
                + timezone.getID()
                + ", "
                + client
                + ", "
                + annotationText
                + ", "
                + annotationId.toString(),
            e);
      }

      // Commit the transaction.
      try {
        transactionManager.commit(status);
      } catch (TransactionException e) {
        transactionManager.rollback(status);
        throw new DataAccessException("Error while committing the transaction.", e);
      }
    } catch (TransactionException e) {
      throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
  }
コード例 #3
0
  public HiveMetadata(
      HiveConnectorId connectorId,
      HiveMetastore metastore,
      HdfsEnvironment hdfsEnvironment,
      DateTimeZone timeZone,
      boolean allowDropTable,
      boolean allowRenameTable,
      boolean allowCorruptWritesForTesting,
      HiveStorageFormat hiveStorageFormat,
      TypeManager typeManager) {
    this.connectorId = checkNotNull(connectorId, "connectorId is null").toString();

    this.allowDropTable = allowDropTable;
    this.allowRenameTable = allowRenameTable;
    this.allowCorruptWritesForTesting = allowCorruptWritesForTesting;

    this.metastore = checkNotNull(metastore, "metastore is null");
    this.hdfsEnvironment = checkNotNull(hdfsEnvironment, "hdfsEnvironment is null");
    this.timeZone = checkNotNull(timeZone, "timeZone is null");
    this.hiveStorageFormat = hiveStorageFormat;
    this.typeManager = checkNotNull(typeManager, "typeManager is null");

    if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) {
      log.warn(
          "Hive writes are disabled. "
              + "To write data to Hive, your JVM timezone must match the Hive storage timezone. "
              + "Add -Duser.timezone=%s to your JVM arguments",
          timeZone.getID());
    }
  }
コード例 #4
0
 /**
  * Gets a debugging toString.
  *
  * @return a debugging string
  */
 public String toString() {
   String str = "BuddhistChronology";
   DateTimeZone zone = getZone();
   if (zone != null) {
     str = str + '[' + zone.getID() + ']';
   }
   return str;
 }
コード例 #5
0
ファイル: DateTimeZone_Test.java プロジェクト: rr-develop/MPS
  public void test_dataFlowCheck() throws Exception {
    DateTimeZone tz1 = DateTimeZone.forID("Europe/Athens");
    tz1.getID();

    Long n = System.currentTimeMillis();
    DateTimeZone tz2 = DateTimeZone.forID("Europe/Amsterdam");
    tz2.getName(n, null);
  }
コード例 #6
0
 private void verifyJvmTimeZone() {
   if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) {
     throw new PrestoException(
         HIVE_TIMEZONE_MISMATCH,
         format(
             "To write Hive data, your JVM timezone must match the Hive storage timezone. Add -Duser.timezone=%s to your JVM arguments.",
             timeZone.getID()));
   }
 }
コード例 #7
0
ファイル: DateTimeZone_Test.java プロジェクト: rr-develop/MPS
 public void test_timeZoneFromString() throws Exception {
   Long nn = System.currentTimeMillis();
   String tz = "Europe/Berlin";
   DateTimeZone tzz = DateTimeZone.forID(tz);
   DateTime inberl = DateTimeOperations.convert(nn, DateTimeZone.forID(tz));
   Assert.assertEquals(inberl, DateTimeOperations.convert(nn, tzz));
   Assert.assertEquals("Europe/Berlin", tzz.getID());
   Assert.assertEquals("Europe/Moscow", DateTimeZone.forID("Europe/Moscow").getID());
 }
コード例 #8
0
ファイル: DateTimeZone_Test.java プロジェクト: rr-develop/MPS
 public void test_prague() throws Exception {
   DateTimeZone prg = DateTimeZone.forID("Europe/Prague");
   Assert.assertEquals(prg, DateTimeZone.forID(prg.getID()));
   Assert.assertEquals("Europe/Prague", prg.getID());
   Assert.assertEquals(
       "Central European Time",
       prg.getName(DateTimeOperations.convert(new DateTime(2008, 1, 1, 12, 0, 0, 0, prg)), null));
   Assert.assertEquals(
       "CET",
       prg.getShortName(
           DateTimeOperations.convert(new DateTime(2008, 1, 1, 12, 0, 0, 0, prg)), null));
   Assert.assertEquals(
       "Central European Summer Time",
       prg.getName(DateTimeOperations.convert(new DateTime(2008, 7, 1, 12, 0, 0, 0, prg)), null));
   Assert.assertEquals(
       "CEST",
       prg.getShortName(
           DateTimeOperations.convert(new DateTime(2008, 7, 1, 12, 0, 0, 0, prg)), null));
 }
コード例 #9
0
 public CreateUserRequest(User user) {
   this.username = user.getName();
   this.fullname = user.getFullName();
   this.email = user.getEmail();
   this.password = "";
   this.permissions = user.getPermissions();
   final DateTimeZone timeZone = user.getTimeZone();
   if (timezone != null) {
     this.timezone = timeZone.getID();
   }
   this.sessionTimeoutMs = user.getSessionTimeoutMs();
 }
コード例 #10
0
ファイル: DateTimeZone_Test.java プロジェクト: rr-develop/MPS
 public void test_london() throws Exception {
   DateTimeZone london = DateTimeZone.forID("Europe/London");
   Assert.assertEquals(london, DateTimeZone.forID(london.getID()));
   Assert.assertEquals("Europe/London", london.getID());
   Assert.assertEquals(
       "Greenwich Mean Time",
       london.getName(
           DateTimeOperations.convert(new DateTime(2008, 1, 1, 12, 0, 0, 0, london)), null));
   Assert.assertEquals(
       "GMT",
       london.getShortName(
           DateTimeOperations.convert(new DateTime(2008, 1, 1, 12, 0, 0, 0, london)), null));
   Assert.assertEquals(
       "British Summer Time",
       london.getName(
           DateTimeOperations.convert(new DateTime(2008, 7, 1, 12, 0, 0, 0, london)), null));
   Assert.assertEquals(
       "BST",
       london.getShortName(
           DateTimeOperations.convert(new DateTime(2008, 7, 1, 12, 0, 0, 0, london)), null));
 }
 public long set(long instant, int value) {
   long localInstant = iZone.convertUTCToLocal(instant);
   localInstant = iField.set(localInstant, value);
   long result = iZone.convertLocalToUTC(localInstant, false, instant);
   if (get(result) != value) {
     throw new IllegalFieldValueException(
         iField.getType(),
         Integer.valueOf(value),
         "Illegal instant due to time zone offset transition: "
             + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")
                 .print(new Instant(localInstant))
             + " ("
             + iZone.getID()
             + ")");
   }
   return result;
 }
コード例 #12
0
  @Test
  public void testTimeZones() {
    DateTimeZone aDTZ = PDTConfig.getDefaultDateTimeZone();
    assertNotNull(aDTZ);

    aDTZ = PDTConfig.getDateTimeZoneUTC();
    assertNotNull(aDTZ);
    assertEquals("UTC", aDTZ.getID());

    assertNotNull(PDTConfig.getDefaultChronologyUTC());
    assertEquals(PDTConfig.getDateTimeZoneUTC(), PDTConfig.getDefaultChronologyUTC().getZone());

    assertNotNull(PDTConfig.getDefaultChronologyWithoutDateTimeZone());
    assertEquals(
        DateTimeZone.getDefault(), PDTConfig.getDefaultChronologyWithoutDateTimeZone().getZone());

    try {
      // Invalid
      assertFalse(PDTConfig.setDefaultDateTimeZoneID("does not exist").isSuccess());

      // Regular
      assertTrue(PDTConfig.setDefaultDateTimeZoneID("Europe/Berlin").isSuccess());
      assertEquals("Europe/Berlin", PDTConfig.getDefaultDateTimeZone().getID());

      // I hope this is not the standard time zone anywhere
      assertTrue(PDTConfig.setDefaultDateTimeZoneID("UTC").isSuccess());
      assertEquals("UTC", PDTConfig.getDefaultDateTimeZone().getID());

      // The default date time zone was not modified
      assertEquals(
          DateTimeZone.getDefault(), PDTConfig.getDefaultChronologyWithoutDateTimeZone().getZone());

      if (!DateTimeZone.getDefault().getID().equals("UTC")) {
        // And therefore this must not be equal
        assertTrue(
            !PDTConfig.getDefaultDateTimeZone()
                .equals(PDTConfig.getDefaultChronologyWithoutDateTimeZone().getZone()));
      }
    } finally {
      assertTrue(PDTConfig.setDefaultDateTimeZoneID(PDTConfig.DEFAULT_DATETIMEZONEID).isSuccess());
    }
  }
コード例 #13
0
  /** @return false if error. */
  static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
      return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
      long next = tz.nextTransition(millis);
      if (next == millis || next > end) {
        break;
      }

      millis = next;

      int nextOffset = tz.getOffset(millis);
      String nextKey = tz.getNameKey(millis);

      if (offset == nextOffset && key.equals(nextKey)) {
        System.out.println(
            "*d* Error in "
                + tz.getID()
                + " "
                + new DateTime(millis, ISOChronology.getInstanceUTC()));
        return false;
      }

      if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
        System.out.println(
            "*s* Error in "
                + tz.getID()
                + " "
                + new DateTime(millis, ISOChronology.getInstanceUTC())
                + ", nameKey="
                + nextKey);
        return false;
      }

      transitions.add(Long.valueOf(millis));

      offset = nextOffset;
      key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i = transitions.size(); --i >= 0; ) {
      long prev = tz.previousTransition(millis);
      if (prev == millis || prev < end) {
        break;
      }

      millis = prev;

      long trans = transitions.get(i).longValue();

      if (trans - 1 != millis) {
        System.out.println(
            "*r* Error in "
                + tz.getID()
                + " "
                + new DateTime(millis, ISOChronology.getInstanceUTC())
                + " != "
                + new DateTime(trans - 1, ISOChronology.getInstanceUTC()));

        return false;
      }
    }

    return true;
  }
コード例 #14
0
 @Override
 public void serialize(DateTimeZone value, JsonGenerator gen, SerializerProvider provider)
     throws IOException {
   gen.writeString(value.getID());
 }
コード例 #15
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeByte(unit.id());
   out.writeSharedString(preTz.getID());
   out.writeSharedString(postTz.getID());
 }
コード例 #16
0
  @Override
  public void createPromptResponseAnnotation(
      final UUID annotationId,
      final String client,
      final Long time,
      final DateTimeZone timezone,
      final String annotationText,
      Integer promptResponseId,
      String user)
      throws DataAccessException {

    // Create the transaction.
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("Creating a new prompt response annotation.");

    try {
      // Begin the transaction.
      PlatformTransactionManager transactionManager =
          new DataSourceTransactionManager(getDataSource());
      TransactionStatus status = transactionManager.getTransaction(def);
      long id = 0;

      try {
        id = insertAnnotation(annotationId, time, timezone, client, annotationText, user);
      } catch (org.springframework.dao.DataAccessException e) {

        transactionManager.rollback(status);
        throw new DataAccessException(
            "Error while executing SQL '"
                + SQL_INSERT_ANNOTATION
                + "' with parameters: "
                + annotationId
                + ", "
                + time
                + ", "
                + timezone.getID()
                + ", "
                + client
                + ", "
                + ((annotationText.length() > 25)
                    ? annotationText.substring(0, 25) + "..."
                    : annotationText),
            e);
      }
      try {
        // Insert the link between the prompt_response and its annotation
        getJdbcTemplate().update(SQL_INSERT_PROMPT_RESPONSE_ANNOTATION, promptResponseId, id);

      } catch (org.springframework.dao.DataAccessException e) {

        transactionManager.rollback(status);
        throw new DataAccessException(
            "Error while executing SQL '"
                + SQL_INSERT_PROMPT_RESPONSE_ANNOTATION
                + "' with parameters: "
                + promptResponseId
                + ", "
                + id,
            e);
      }

      // Commit the transaction.
      try {
        transactionManager.commit(status);
      } catch (TransactionException e) {
        transactionManager.rollback(status);
        throw new DataAccessException("Error while committing the transaction.", e);
      }

    } catch (TransactionException e) {
      throw new DataAccessException("Error while attempting to rollback the transaction.", e);
    }
  }
コード例 #17
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeVLong(interval);
   out.writeSharedString(preTz.getID());
   out.writeSharedString(postTz.getID());
 }
コード例 #18
0
  /**
   * Returns a map of ids to DateTimeZones.
   *
   * @param outputDir optional directory to write compiled data files to
   * @param sources optional list of source files to parse
   */
  public Map<String, DateTimeZone> compile(File outputDir, File[] sources) throws IOException {
    if (sources != null) {
      for (int i = 0; i < sources.length; i++) {
        BufferedReader in = new BufferedReader(new FileReader(sources[i]));
        parseDataFile(in);
        in.close();
      }
    }

    if (outputDir != null) {
      if (!outputDir.exists()) {
        if (!outputDir.mkdirs()) {
          throw new IOException(
              "Destination directory doesn't exist and cannot be created: " + outputDir);
        }
      }
      if (!outputDir.isDirectory()) {
        throw new IOException("Destination is not a directory: " + outputDir);
      }
    }

    Map<String, DateTimeZone> map = new TreeMap<String, DateTimeZone>();

    System.out.println("Writing zoneinfo files");
    for (int i = 0; i < iZones.size(); i++) {
      Zone zone = iZones.get(i);
      DateTimeZoneBuilder builder = new DateTimeZoneBuilder();
      zone.addToBuilder(builder, iRuleSets);
      final DateTimeZone original = builder.toDateTimeZone(zone.iName, true);
      DateTimeZone tz = original;
      if (test(tz.getID(), tz)) {
        map.put(tz.getID(), tz);
        if (outputDir != null) {
          if (ZoneInfoCompiler.verbose()) {
            System.out.println("Writing " + tz.getID());
          }
          File file = new File(outputDir, tz.getID());
          if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
          }
          OutputStream out = new FileOutputStream(file);
          try {
            builder.writeTo(zone.iName, out);
          } finally {
            out.close();
          }

          // Test if it can be read back.
          InputStream in = new FileInputStream(file);
          DateTimeZone tz2 = DateTimeZoneBuilder.readFrom(in, tz.getID());
          in.close();

          if (!original.equals(tz2)) {
            System.out.println("*e* Error in " + tz.getID() + ": Didn't read properly from file");
          }
        }
      }
    }

    for (int pass = 0; pass < 2; pass++) {
      for (int i = 0; i < iLinks.size(); i += 2) {
        String id = iLinks.get(i);
        String alias = iLinks.get(i + 1);
        DateTimeZone tz = map.get(id);
        if (tz == null) {
          if (pass > 0) {
            System.out.println(
                "Cannot find time zone '" + id + "' to link alias '" + alias + "' to");
          }
        } else {
          map.put(alias, tz);
        }
      }
    }

    if (outputDir != null) {
      System.out.println("Writing ZoneInfoMap");
      File file = new File(outputDir, "ZoneInfoMap");
      if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
      }

      OutputStream out = new FileOutputStream(file);
      DataOutputStream dout = new DataOutputStream(out);
      try {
        // Sort and filter out any duplicates that match case.
        Map<String, DateTimeZone> zimap =
            new TreeMap<String, DateTimeZone>(String.CASE_INSENSITIVE_ORDER);
        zimap.putAll(map);
        writeZoneInfoMap(dout, zimap);
      } finally {
        dout.close();
      }
    }

    return map;
  }
コード例 #19
0
ファイル: JodaInstantVO.java プロジェクト: egustafson/sandbox
 public void setTimezone(DateTimeZone timezone) {
   this.timezone = (timezone == null ? null : timezone.getID());
 }