@Override
 public void extractValues(T facet, TimeInterval timeInterval, GuestSettings settings)
     throws OutsideTimeBoundariesException {
   super.extractValues(facet, timeInterval, settings);
   this.eventStart =
       ISODateTimeFormat.dateTime()
           .withZone(DateTimeZone.forTimeZone(timeInterval.getTimeZone(facet.start)))
           .print(facet.start);
   this.eventEnd =
       ISODateTimeFormat.dateTime()
           .withZone(DateTimeZone.forTimeZone(timeInterval.getTimeZone(facet.end)))
           .print(facet.end);
 }
Ejemplo n.º 2
0
  public static void main(String args[]) {

    TimeZone.setDefault(TimeZone.getTimeZone("America/Bogota"));

    DateTime dt = new DateTime();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //		System.out.println("- " + sdf.format(dt.toDate()));
    //		sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    //		System.out.println("- " + sdf.format(dt.toDate()));

    String sd = "2011-03-18 16:30:39";
    sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    Date d = null;
    try {
      d = sdf.parse(sd);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println("- " + sdf.format(d));
    sdf.setTimeZone(TimeZone.getTimeZone("America/Bogota"));
    System.out.println("- " + sdf.format(d));

    try {
      d = sdf.parse(sd);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println("- " + sdf.format(d));

    DateTime nDt = dt.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai")));
    System.out.println(sdf.format(nDt.toDate()));

    DateTime dt2 = new DateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Tokyo")));

    sdf.setTimeZone(TimeZone.getTimeZone("America/Bogota"));
    System.out.println(sdf.format(dt2.toDate()));

    //		System.out.println(getFormatedDateString(""));
    //		System.out.println(getFormatedDateString("America/Bogota"));
    //
    //		//printSysProperties();
    //
    //		System.out.println("------------------------------------------");
    ////		System.setProperty("user.timezone", "America/Bogota");
    //		TimeZone.setDefault(TimeZone.getTimeZone("America/Bogota"));
    //
    //		System.out.println(getFormatedDateString(""));
    //		System.out.println(getFormatedDateString("Asia/Shanghai"));

    // printSysProperties();
  }
Ejemplo n.º 3
0
 @JsonIgnore // Don't persist ov
 public DateTime getFortressUpdatedTz() {
   if (fortressLastWhen == null) return null;
   return new DateTime(
       fortressLastWhen,
       DateTimeZone.forTimeZone(TimeZone.getTimeZone(segment.getFortress().getTimeZone())));
 }
Ejemplo n.º 4
0
  public static DateTimeZone getTimeZone(Ruby runtime, String zone) {
    DateTimeZone cachedZone = runtime.getTimezoneCache().get(zone);

    if (cachedZone != null) return cachedZone;

    String originalZone = zone;
    TimeZone tz = TimeZone.getTimeZone(getEnvTimeZone(runtime).toString());

    // Value of "TZ" property is of a bit different format,
    // which confuses the Java's TimeZone.getTimeZone(id) method,
    // and so, we need to convert it.

    Matcher tzMatcher = TZ_PATTERN.matcher(zone);
    if (tzMatcher.matches()) {
      String sign = tzMatcher.group(2);
      String hours = tzMatcher.group(3);
      String minutes = tzMatcher.group(4);

      // GMT+00:00 --> Etc/GMT, see "MRI behavior"
      // comment below.
      if (("00".equals(hours) || "0".equals(hours))
          && (minutes == null || ":00".equals(minutes) || ":0".equals(minutes))) {
        zone = "Etc/GMT";
      } else {
        // Invert the sign, since TZ format and Java format
        // use opposite signs, sigh... Also, Java API requires
        // the sign to be always present, be it "+" or "-".
        sign = ("-".equals(sign) ? "+" : "-");

        // Always use "GMT" since that's required by Java API.
        zone = "GMT" + sign + hours;

        if (minutes != null) {
          zone += minutes;
        }
      }

      tz = TimeZone.getTimeZone(zone);
    } else {
      if (LONG_TZNAME.containsKey(zone)) tz.setID(LONG_TZNAME.get(zone.toUpperCase()));
    }

    // MRI behavior: With TZ equal to "GMT" or "UTC", Time.now
    // is *NOT* considered as a proper GMT/UTC time:
    //   ENV['TZ']="GMT"
    //   Time.now.gmt? ==> false
    //   ENV['TZ']="UTC"
    //   Time.now.utc? ==> false
    // Hence, we need to adjust for that.
    if ("GMT".equalsIgnoreCase(zone) || "UTC".equalsIgnoreCase(zone)) {
      zone = "Etc/" + zone;
      tz = TimeZone.getTimeZone(zone);
    }

    DateTimeZone dtz = DateTimeZone.forTimeZone(tz);
    runtime.getTimezoneCache().put(originalZone, dtz);
    return dtz;
  }
Ejemplo n.º 5
0
  public static Date stringToDateWithZone(String isoDate) {
    DateTime dt = null;

    if (Strings.isEmpty(isoDate)) return null;

    try {
      dt = new DateTime(isoDate, DateTimeZone.forTimeZone(TimeZone.getDefault()));
    } catch (IllegalArgumentException e) {
      if (isoDate.indexOf(' ') > 0) isoDate = isoDate.replace(' ', 'T');
      try {
        dt = new DateTime(isoDate, DateTimeZone.forTimeZone(TimeZone.getDefault()));
      } catch (IllegalArgumentException ex) {
        log.error("parameter error");
      }
    }
    if (dt == null) return null;

    return dt.toDate();
  }
Ejemplo n.º 6
0
  @Override
  public void onStart(ITestContext context) {
    CommonUtils.createDirectory(screenDirPath);
    imageCounter = 0;
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();

    StringBuilder builder = new StringBuilder();
    builder.append(
        "<html><style>"
            + "table {margin:0 auto;}td:first-child {width:200px;}td:nth-child(2) {width:660px;}td:nth-child(3) "
            + "{width:100px;}tr.success{color:black;background-color:#CCFFCC;}"
            + "tr.warning{color:black;background-color:#FEE01E;}"
            + "tr.error{color:black;background-color:#FFCCCC;}"
            + "tr.step{color:white;background:grey}"
            + "</style><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
            + "<style>td { border-top: 1px solid grey; } </style></head><body>"
            + "<script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.8.2.min.js\"></script>"
            + "<p>Date: "
            + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ")
                .print(DateTime.now(DateTimeZone.UTC))
            + "</p>"
            + "<p>Polish Time: "
            + DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss ZZ")
                .print(
                    DateTime.now()
                        .withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/Warsaw"))))
            + "</p>"
            + "<p>Browser: "
            + Configuration.getBrowser()
            + "</p>"
            + "<p>OS: "
            + System.getProperty("os.name")
            + "</p>"
            + "<p>Testing environment: "
            + new UrlBuilder().getUrlForWiki(Configuration.getWikiName())
            + "</p>"
            + "<p>Testing environment: "
            + Configuration.getEnv()
            + "</p>"
            + "<p>Tested version: "
            + "TO DO: GET WIKI VERSION HERE"
            + "</p>"
            + "<div id='toc'></div>");
    CommonUtils.appendTextToFile(logPath, builder.toString());
    appendShowHideButtons();
    try {
      FileInputStream input = new FileInputStream("./src/test/resources/script.txt");
      String content = IOUtils.toString(input);
      CommonUtils.appendTextToFile(logPath, content);
    } catch (IOException e) {
      System.out.println("no script.txt file available");
    }
  }
 /** Asserts that two API date times are equal. */
 private static void assertEquals(
     com.google.api.ads.dfp.jaxws.v201306.DateTime expected,
     com.google.api.ads.dfp.jaxws.v201306.DateTime actual) {
   boolean equals =
       expected == actual
           || new EqualsBuilder()
               .append(expected.getDate().getYear(), actual.getDate().getYear())
               .append(expected.getDate().getMonth(), actual.getDate().getMonth())
               .append(expected.getDate().getDay(), actual.getDate().getDay())
               .append(expected.getHour(), actual.getHour())
               .append(expected.getMinute(), actual.getMinute())
               .append(expected.getSecond(), actual.getSecond())
               .append(
                   DateTimeZone.forTimeZone(TimeZone.getTimeZone(expected.getTimeZoneID()))
                       .toTimeZone()
                       .getRawOffset(),
                   DateTimeZone.forTimeZone(TimeZone.getTimeZone(actual.getTimeZoneID()))
                       .toTimeZone()
                       .getRawOffset())
               .isEquals();
   Assert.assertTrue(
       String.format("Expected: <%s> Actual: <%s>", toString(expected), toString(actual)), equals);
 }
Ejemplo n.º 8
0
 @Inject
 @SuppressWarnings("deprecation")
 public HiveMetadata(
     HiveConnectorId connectorId,
     HiveClientConfig hiveClientConfig,
     HiveMetastore metastore,
     HdfsEnvironment hdfsEnvironment,
     @ForHiveClient ExecutorService executorService,
     TypeManager typeManager) {
   this(
       connectorId,
       metastore,
       hdfsEnvironment,
       DateTimeZone.forTimeZone(hiveClientConfig.getTimeZone()),
       hiveClientConfig.getAllowDropTable(),
       hiveClientConfig.getAllowRenameTable(),
       hiveClientConfig.getAllowCorruptWritesForTesting(),
       hiveClientConfig.getHiveStorageFormat(),
       typeManager);
 }
Ejemplo n.º 9
0
  public static TimezoneMap fromConsensusTimezoneMap(
      final TreeMap<String, TimeZone> consensusTimezoneMap) {
    TimezoneMap timezoneMap = new TimezoneMap();
    Long holdStartMillis = null;
    DateTimeZone holdDateTimezone = null;
    Long lastEndMillis = null;

    for (String date : consensusTimezoneMap.keySet()) {
      final TimeZone timeZone = consensusTimezoneMap.get(date);
      final DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);
      final DateTime thisStartDateTime =
          TimeUtils.dateFormatter.withZone(dateTimeZone).parseDateTime(date);
      final long thisStartMillis = thisStartDateTime.getMillis();

      // Check if we need to flush a prior segment
      if (holdStartMillis != null && holdDateTimezone != dateTimeZone) {
        // Yes, this differs, end the previous segment with holdStartMillis as its
        // start time and thisStartMillis-1 as its end time
        timezoneMap.add(holdStartMillis, thisStartMillis - 1, holdDateTimezone);
        // Update holdStartMillis and holdDateTimezone for next time to be the start of this segment
        holdStartMillis = thisStartMillis;
        holdDateTimezone = dateTimeZone;
      } else if (holdStartMillis == null) {
        // This is the first time through, hold onto holdStartMillis and holdDateTimezone
        // for next time to be the start of the first  segment
        holdStartMillis = thisStartMillis;
        holdDateTimezone = dateTimeZone;
      } else {
        // Continue with the earlier timezone, no need to change anything
      }
      // Update lastEndMillis for closing up on the last segment
      lastEndMillis = thisStartMillis + DateTimeConstants.MILLIS_PER_DAY;
    }
    // Flush the last segment (unless it's empty)
    if (holdDateTimezone != null) {
      timezoneMap.add(holdStartMillis, lastEndMillis, holdDateTimezone);
    }
    return timezoneMap;
  }
Ejemplo n.º 10
0
 public static Date dataHora(String dataHora, TimeZone timezone) {
   return dataHora(dataHora, DateTimeZone.forTimeZone(timezone));
 }
Ejemplo n.º 11
0
  protected void setupHive(String connectorId, String databaseName, String timeZoneId) {
    database = databaseName;
    table = new SchemaTableName(database, "presto_test");
    tableUnpartitioned = new SchemaTableName(database, "presto_test_unpartitioned");
    tableOffline = new SchemaTableName(database, "presto_test_offline");
    tableOfflinePartition = new SchemaTableName(database, "presto_test_offline_partition");
    view = new SchemaTableName(database, "presto_test_view");
    invalidTable = new SchemaTableName(database, INVALID_TABLE);
    tableBucketedStringInt = new SchemaTableName(database, "presto_test_bucketed_by_string_int");
    tableBucketedBigintBoolean =
        new SchemaTableName(database, "presto_test_bucketed_by_bigint_boolean");
    tableBucketedDoubleFloat =
        new SchemaTableName(database, "presto_test_bucketed_by_double_float");

    temporaryCreateTable = new SchemaTableName(database, "tmp_presto_test_create_" + randomName());
    temporaryCreateSampledTable =
        new SchemaTableName(database, "tmp_presto_test_create_" + randomName());
    temporaryCreateView = new SchemaTableName(database, "tmp_presto_test_create_" + randomName());
    tableOwner = "presto_test";

    invalidTableHandle = new HiveTableHandle("hive", database, INVALID_TABLE, SESSION);

    dsColumn = new HiveColumnHandle(connectorId, "ds", 0, HiveType.STRING, -1, true);
    fileFormatColumn =
        new HiveColumnHandle(connectorId, "file_format", 1, HiveType.STRING, -1, true);
    dummyColumn = new HiveColumnHandle(connectorId, "dummy", 2, HiveType.INT, -1, true);
    intColumn = new HiveColumnHandle(connectorId, "t_int", 0, HiveType.INT, -1, true);
    invalidColumnHandle =
        new HiveColumnHandle(connectorId, INVALID_COLUMN, 0, HiveType.STRING, 0, false);

    partitions =
        ImmutableSet.<ConnectorPartition>of(
            new HivePartition(
                table,
                "ds=2012-12-29/file_format=rcfile-text/dummy=0",
                ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(
                    dsColumn,
                    utf8Slice("2012-12-29"),
                    fileFormatColumn,
                    utf8Slice("rcfile-text"),
                    dummyColumn,
                    0L),
                Optional.<HiveBucket>absent()),
            new HivePartition(
                table,
                "ds=2012-12-29/file_format=rcfile-binary/dummy=2",
                ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(
                    dsColumn,
                    utf8Slice("2012-12-29"),
                    fileFormatColumn,
                    utf8Slice("rcfile-binary"),
                    dummyColumn,
                    2L),
                Optional.<HiveBucket>absent()),
            new HivePartition(
                table,
                "ds=2012-12-29/file_format=sequencefile/dummy=4",
                ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(
                    dsColumn,
                    utf8Slice("2012-12-29"),
                    fileFormatColumn,
                    utf8Slice("sequencefile"),
                    dummyColumn,
                    4L),
                Optional.<HiveBucket>absent()),
            new HivePartition(
                table,
                "ds=2012-12-29/file_format=textfile/dummy=6",
                ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(
                    dsColumn,
                    utf8Slice("2012-12-29"),
                    fileFormatColumn,
                    utf8Slice("textfile"),
                    dummyColumn,
                    6L),
                Optional.<HiveBucket>absent()));
    unpartitionedPartitions =
        ImmutableSet.<ConnectorPartition>of(new HivePartition(tableUnpartitioned));
    invalidPartition =
        new HivePartition(
            invalidTable,
            "unknown",
            ImmutableMap.<ConnectorColumnHandle, Comparable<?>>of(),
            Optional.<HiveBucket>absent());
    timeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId));
  }
Ejemplo n.º 12
0
 public static synchronized void setTimeZone(TimeZone timeZone) {
   Environment.timeZone = DateTimeZone.forTimeZone(timeZone);
 }
Ejemplo n.º 13
0
 public static String format(DateTime toFormat, TimeZone tz) {
   return LOCAL_SUB_SECOND_FMT.withZone(DateTimeZone.forTimeZone(tz)).print(toFormat.getMillis());
 }
Ejemplo n.º 14
0
 @JsonIgnore
 public DateTime getFortressCreatedTz() {
   return new DateTime(
       fortressCreate,
       DateTimeZone.forTimeZone(TimeZone.getTimeZone(segment.getFortress().getTimeZone())));
 }
Ejemplo n.º 15
0
  public Entity(
      String metaKey,
      FortressSegment segment,
      @NotEmpty EntityInputBean entityInput,
      @NotEmpty DocumentType documentType)
      throws FlockException {
    this();

    assert documentType != null;
    assert segment != null;

    labels.add(documentType.getName());
    this.metaKey = metaKey;
    this.noLogs = entityInput.isEntityOnly();
    this.segment = segment; // (FortressNode)documentType.getFortress();
    // DAT-278
    String docType = documentType.getName();
    if (docType == null) docType = documentType.getCode();

    if (docType == null)
      throw new RuntimeException(
          "Unable to resolve the doc type code [" + documentType + "] for  " + entityInput);

    newEntity = true;

    docType = docType.toLowerCase();
    code = entityInput.getCode();
    key =
        EntityHelper.parseKey(
            this.segment.getFortress().getId(),
            documentType.getId(),
            (code != null ? code : this.metaKey));
    // key = this.fortress.getId() + "." + documentType.getId() + "." + (code != null ? code :
    // metaKey);

    if (entityInput.getName() == null || entityInput.getName().equals(""))
      this.name = (code == null ? docType : (docType + "." + code));
    else this.name = entityInput.getName();

    //        if ( entityInput.getDescription()!=null &&
    // !entityInput.getDescription().equals(entityInput.getName()))
    //            this.description = entityInput.getDescription();

    //        indexName = indexHelper.getIndexRoot(this.segment);

    if (entityInput.getProperties() != null && !entityInput.getProperties().isEmpty()) {
      props = new DynamicPropertiesContainer(entityInput.getProperties());
    }

    Date when = entityInput.getWhen();

    if (when == null)
      fortressCreate =
          new DateTime(
                  dateCreated,
                  DateTimeZone.forTimeZone(
                      TimeZone.getTimeZone(this.segment.getFortress().getTimeZone())))
              .getMillis();
    else
      fortressCreate =
          new DateTime(when.getTime())
              .getMillis(); // new DateTime( when.getTime(),
                            // DateTimeZone.forTimeZone(TimeZone.getTimeZone(entityInput.getMetaTZ()))).toDate().getTime();
    if (entityInput.getLastChange() != null) {
      long fWhen = entityInput.getLastChange().getTime();
      if (fWhen != fortressCreate) fortressLastWhen = fWhen;
    }

    // Content date has the last say on when the update happened
    if (entityInput.getContent() != null && entityInput.getContent().getWhen() != null) {
      fortressLastWhen = entityInput.getContent().getWhen().getTime();
    }

    // lastUpdate = 0l;
    if (entityInput.isEntityOnly()) this.event = entityInput.getEvent();
    this.suppressSearch(entityInput.isSearchSuppressed());
  }
Ejemplo n.º 16
0
 public CalendarTimeZone(TimeZone zone) {
   jodaTimeZone = DateTimeZone.forTimeZone(zone);
 }
Ejemplo n.º 17
0
 @Before
 public void setup() {
   originalTimeZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
   DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT")));
 }
Ejemplo n.º 18
0
 public static String dateToString(Calendar date) {
   return iso8601Formatter.print(
       new DateTime(date.getTimeInMillis(), DateTimeZone.forTimeZone(date.getTimeZone())));
 }
Ejemplo n.º 19
0
 public static String formatarComTimezone(Date date, TimeZone timezone) {
   return formatarComTimezone(date, DateTimeZone.forTimeZone(timezone));
 }
Ejemplo n.º 20
0
 @After
 public void after() {
   TimeZone.setDefault(originalTimeZone);
   DateTimeZone.setDefault(DateTimeZone.forTimeZone(originalTimeZone));
 }
Ejemplo n.º 21
0
 private long getMillis(final LocalDate date) {
   return date.toDateTimeAtStartOfDay(DateTimeZone.forTimeZone(getTimeZone(date))).getMillis();
 }
Ejemplo n.º 22
0
 private DateTimeZone getBrowserDateTimeZone() {
   // TODO: This doesn't match the implementation, even though it should be right
   final TimeZone tz = metadataService.getCurrentTimeZone(guestId);
   return DateTimeZone.forTimeZone(tz);
 }