List of usage examples for java.util GregorianCalendar setTimeZone
@Override public void setTimeZone(TimeZone zone)
From source file:test.unit.be.e_contract.dssp.client.DigitalSignatureServiceTestPort.java
@Override public ResponseBaseType verify(VerifyRequest verifyRequest) { ResponseBaseType response = this.objectFactory.createResponseBaseType(); response.setProfile(DigitalSignatureServiceConstants.PROFILE); Result result = this.objectFactory.createResult(); response.setResult(result);/*from w ww . j a va 2 s . com*/ result.setResultMajor(DigitalSignatureServiceConstants.SUCCESS_RESULT_MAJOR); AnyType optionalOutputs = this.objectFactory.createAnyType(); response.setOptionalOutputs(optionalOutputs); VerificationReportType verificationReport = this.vrObjectFactory.createVerificationReportType(); optionalOutputs.getAny().add(this.vrObjectFactory.createVerificationReport(verificationReport)); DeadlineType timeStampRenewalDeadline = this.dsspObjectFactory.createDeadlineType(); GregorianCalendar beforeGregorianCalendar = new GregorianCalendar(); beforeGregorianCalendar.setTime(new Date()); beforeGregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); XMLGregorianCalendar beforeXMLGregorianCalendar = this.datatypeFactory .newXMLGregorianCalendar(beforeGregorianCalendar); timeStampRenewalDeadline.setBefore(beforeXMLGregorianCalendar); optionalOutputs.getAny().add(this.dsspObjectFactory.createTimeStampRenewal(timeStampRenewalDeadline)); IndividualReportType individualReport = this.vrObjectFactory.createIndividualReportType(); verificationReport.getIndividualReport().add(individualReport); individualReport.setResult(result); SignedObjectIdentifierType signedObjectIdentifier = this.vrObjectFactory.createSignedObjectIdentifierType(); individualReport.setSignedObjectIdentifier(signedObjectIdentifier); SignedPropertiesType signedProperties = this.vrObjectFactory.createSignedPropertiesType(); signedObjectIdentifier.setSignedProperties(signedProperties); SignedSignaturePropertiesType signedSignatureProperties = this.vrObjectFactory .createSignedSignaturePropertiesType(); signedProperties.setSignedSignatureProperties(signedSignatureProperties); GregorianCalendar signingTimeGregorianCalendar = new GregorianCalendar(); signingTimeGregorianCalendar.setTime(new Date()); signingTimeGregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); XMLGregorianCalendar signingTimeXMLGregorianCalendar = this.datatypeFactory .newXMLGregorianCalendar(signingTimeGregorianCalendar); signedSignatureProperties.setSigningTime(signingTimeXMLGregorianCalendar); AnyType details = this.objectFactory.createAnyType(); individualReport.setDetails(details); DetailedSignatureReportType detailedSignatureReport = this.vrObjectFactory .createDetailedSignatureReportType(); details.getAny().add(this.vrObjectFactory.createDetailedSignatureReport(detailedSignatureReport)); VerificationResultType formatOKVerificationResult = this.vrObjectFactory.createVerificationResultType(); formatOKVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); detailedSignatureReport.setFormatOK(formatOKVerificationResult); SignatureValidityType signatureOkSignatureValidity = this.vrObjectFactory.createSignatureValidityType(); detailedSignatureReport.setSignatureOK(signatureOkSignatureValidity); VerificationResultType sigMathOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); signatureOkSignatureValidity.setSigMathOK(sigMathOkVerificationResult); sigMathOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); CertificatePathValidityType certificatePathValidity = this.vrObjectFactory .createCertificatePathValidityType(); detailedSignatureReport.setCertificatePathValidity(certificatePathValidity); VerificationResultType certPathVerificationResult = this.vrObjectFactory.createVerificationResultType(); certPathVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); certificatePathValidity.setPathValiditySummary(certPathVerificationResult); X509IssuerSerialType certificateIdentifier = this.xmldsigObjectFactory.createX509IssuerSerialType(); certificatePathValidity.setCertificateIdentifier(certificateIdentifier); certificateIdentifier.setX509IssuerName("CN=Issuer"); certificateIdentifier.setX509SerialNumber(BigInteger.ONE); CertificatePathValidityVerificationDetailType certificatePathValidityVerificationDetail = this.vrObjectFactory .createCertificatePathValidityVerificationDetailType(); certificatePathValidity.setPathValidityDetail(certificatePathValidityVerificationDetail); CertificateValidityType certificateValidity = this.vrObjectFactory.createCertificateValidityType(); certificatePathValidityVerificationDetail.getCertificateValidity().add(certificateValidity); certificateValidity.setCertificateIdentifier(certificateIdentifier); certificateValidity.setSubject("CN=Subject"); VerificationResultType chainingOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateValidity.setChainingOK(chainingOkVerificationResult); chainingOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); VerificationResultType validityPeriodOkVerificationResult = this.vrObjectFactory .createVerificationResultType(); certificateValidity.setValidityPeriodOK(validityPeriodOkVerificationResult); validityPeriodOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); VerificationResultType extensionsOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateValidity.setExtensionsOK(extensionsOkVerificationResult); extensionsOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); byte[] encodedCertificate; try { encodedCertificate = IOUtils .toByteArray(DigitalSignatureServiceTestPort.class.getResource("/fcorneli.der")); } catch (IOException e) { throw new RuntimeException(e); } certificateValidity.setCertificateValue(encodedCertificate); certificateValidity.setSignatureOK(signatureOkSignatureValidity); CertificateStatusType certificateStatus = this.vrObjectFactory.createCertificateStatusType(); certificateValidity.setCertificateStatus(certificateStatus); VerificationResultType certStatusOkVerificationResult = this.vrObjectFactory.createVerificationResultType(); certificateStatus.setCertStatusOK(certStatusOkVerificationResult); certStatusOkVerificationResult.setResultMajor(DigitalSignatureServiceConstants.VR_RESULT_MAJOR_VALID); return response; }
From source file:org.jfree.data.time.WeekTest.java
/** * Some checks for the getFirstMillisecond(TimeZone) method. *//*from w w w. j a v a 2 s . co m*/ @Test public void testGetFirstMillisecondWithCalendar() { Week w = new Week(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, w.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { w.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.time.WeekTest.java
/** * Some checks for the getLastMillisecond(TimeZone) method. *//* www . j a v a2s .c o m*/ @Test public void testGetLastMillisecondWithCalendar() { Week w = new Week(52, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1009756799999L, w.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { w.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
From source file:ca.uhn.hl7v2.model.primitive.tests.CommonTMTest.java
@Test public void testToHl7TMFormat() throws DataTypeException, ParseException { //new tests related to bug 1173074 ... //case 1: Paris time, date in winter java.util.Date date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950305000000+0000"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); cal.setTime(date);/* w w w.j a v a 2 s .c om*/ assertEquals("19950305010000+0100", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 2: Paris time, date in summer date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950805000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); cal.setTime(date); assertEquals("19950805020000+0200", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 3: New York time, date in winter date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950305000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("America/New_York")); cal.setTime(date); assertEquals("19950304190000-0500", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 4: New York time, date in summer date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950805000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("America/New_York")); cal.setTime(date); assertEquals("19950804200000-0400", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); }
From source file:net.acesinc.nifi.processors.security.ConvertSecurityMarkingAndAttrListIntoJson.java
/** * Builds the Map of attributes that should be included in the JSON that is * emitted from this process.//from w w w. jav a2s . co m * * @param ff * @param rawSecurityMarking * @param atrListForStringValues * @param atrListForIntValues * @param atrListForDoubleValues * @param atrListForLongEpochToGoToDateValues * @param secConfig * @return Map of values that are feed to a Jackson ObjectMapper * @throws java.io.IOException */ protected Map<String, Object> buildSecurityAttributesMapForFlowFileAndBringInFlowAttrs(FlowFile ff, String rawSecurityMarking, String atrListForStringValues, String atrListForIntValues, String atrListForDoubleValues, String atrListForLongEpochToGoToDateValues, FlowAttrSecurityConfig secConfig) throws IOException { final ComponentLog logger = getLogger(); Map<String, Object> atsToWrite = new HashMap<>(); //handle all the string values //If list of attributes specified get only those attributes. Otherwise write them all if (StringUtils.isNotBlank(atrListForStringValues)) { String[] ats = StringUtils.split(atrListForStringValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, val); } else { atsToWrite.put(cleanStr, ""); } } } } else { atsToWrite.putAll(ff.getAttributes()); } //handle all int values if (StringUtils.isNotBlank(atrListForIntValues)) { String[] ats = StringUtils.split(atrListForIntValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, Integer.parseInt(val)); } else { atsToWrite.put(cleanStr, null); } } } } //handle all double values if (StringUtils.isNotBlank(atrListForDoubleValues)) { String[] ats = StringUtils.split(atrListForDoubleValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, Double.parseDouble(val)); } else { atsToWrite.put(cleanStr, null); } } } } //handle all date values if (StringUtils.isNotBlank(atrListForLongEpochToGoToDateValues)) { String[] ats = StringUtils.split(atrListForLongEpochToGoToDateValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { long epochTime = Long.parseLong(val); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeZone(TimeZone.getTimeZone(MONGO_TIME_ZONE)); gcal.setTimeInMillis(epochTime); SimpleDateFormat sdf = new SimpleDateFormat(MONGO_DATE_TEMPLATE); String mongoDate = sdf.format(gcal.getTime()); //to Date Map<String, String> isoDate = new HashMap<>(); isoDate.put("$date", mongoDate); atsToWrite.put(cleanStr, isoDate); } else { atsToWrite.put(cleanStr, null); } } } } //build the classification object for json if (StringUtils.isNotBlank(rawSecurityMarking)) { Classification classification = new Classification(); String cleanRawMarking = rawSecurityMarking.trim(); logger.debug("cleanRawMarking:=" + cleanRawMarking); List<String> levels = convertSecMarkingToLevelsFlowAttr(cleanRawMarking, secConfig); classification.setLevels(levels); List<String> convertedComps = convertSecMarkingToCompartmentsFlowAttr(cleanRawMarking, secConfig); classification.setCompartments(convertedComps); List<String> convertedRels = convertSecMarkingToReleasabilitiesFlowAttr(cleanRawMarking, secConfig); classification.setReleasabilities(convertedRels); List<String> convertedDissems = convertSecMarkingToDissemControlsFlowAttr(cleanRawMarking, secConfig); classification.setDisseminationControls(convertedDissems); atsToWrite.put("classification", classification); } else { //should not get here, but if we do, we need to throw illegal state as we should not be ingesting w/o classification, but instead force configuration changes throw new IllegalStateException( "This processor is reaching an illegal state. Please adjust configuration for rawSecurityMarking to not be blank or null."); } return atsToWrite; }
From source file:be.fedict.trust.xkms2.XKMSPortImpl.java
private Date getDate(XMLGregorianCalendar xmlCalendar) { GregorianCalendar calendar = new GregorianCalendar(xmlCalendar.getYear(), xmlCalendar.getMonth() - 1, xmlCalendar.getDay(), // xmlCalendar.getHour(), xmlCalendar.getMinute(), xmlCalendar.getSecond()); calendar.setTimeZone(xmlCalendar.getTimeZone(0)); return calendar.getTime(); }
From source file:org.repodriller.scm.GitRepository.java
private GregorianCalendar convertToDate(RevCommit revCommit) { GregorianCalendar date = new GregorianCalendar(); date.setTimeZone(revCommit.getAuthorIdent().getTimeZone()); date.setTime(revCommit.getAuthorIdent().getWhen()); return date;//from w w w . j a v a 2 s . co m }
From source file:org.repodriller.scm.GitRepository.java
/** * Get the commit with this commit id.//from www.j a v a2 s .co m * Caveats: * - If commit modifies more than maxNumberFilesInACommit, throws an exception * - If one of the file diffs exceeds maxSizeOfDiff, the diffText is discarded * * @param id The SHA1 hash that identifies a git commit. * @returns Commit The corresponding Commit, or null. */ @Override public Commit getCommit(String id) { try (Git git = openRepository()) { /* Using JGit, this commit will be the first entry in the log beginning at id. */ Repository repo = git.getRepository(); Iterable<RevCommit> jgitCommits = git.log().add(repo.resolve(id)).call(); Iterator<RevCommit> itr = jgitCommits.iterator(); if (!itr.hasNext()) return null; RevCommit jgitCommit = itr.next(); /* Extract metadata. */ Developer author = new Developer(jgitCommit.getAuthorIdent().getName(), jgitCommit.getAuthorIdent().getEmailAddress()); Developer committer = new Developer(jgitCommit.getCommitterIdent().getName(), jgitCommit.getCommitterIdent().getEmailAddress()); TimeZone authorTimeZone = jgitCommit.getAuthorIdent().getTimeZone(); TimeZone committerTimeZone = jgitCommit.getCommitterIdent().getTimeZone(); String msg = collectConfig.isCollectingCommitMessages() ? jgitCommit.getFullMessage().trim() : ""; String hash = jgitCommit.getName().toString(); List<String> parents = Arrays.stream(jgitCommit.getParents()).map(rc -> rc.getName().toString()) .collect(Collectors.toList()); GregorianCalendar authorDate = new GregorianCalendar(); authorDate.setTime(jgitCommit.getAuthorIdent().getWhen()); authorDate.setTimeZone(jgitCommit.getAuthorIdent().getTimeZone()); GregorianCalendar committerDate = new GregorianCalendar(); committerDate.setTime(jgitCommit.getCommitterIdent().getWhen()); committerDate.setTimeZone(jgitCommit.getCommitterIdent().getTimeZone()); boolean isMerge = (jgitCommit.getParentCount() > 1); Set<String> branches = getBranches(git, hash); boolean isCommitInMainBranch = branches.contains(this.mainBranchName); /* Create one of our Commit's based on the jgitCommit metadata. */ Commit commit = new Commit(hash, author, committer, authorDate, authorTimeZone, committerDate, committerTimeZone, msg, parents, isMerge, branches, isCommitInMainBranch); /* Convert each of the associated DiffEntry's to a Modification. */ List<DiffEntry> diffsForTheCommit = diffsForTheCommit(repo, jgitCommit); if (diffsForTheCommit.size() > maxNumberFilesInACommit) { String errMsg = "Commit " + id + " touches more than " + maxNumberFilesInACommit + " files"; log.error(errMsg); throw new RepoDrillerException(errMsg); } for (DiffEntry diff : diffsForTheCommit) { if (this.diffFiltersAccept(diff)) { Modification m = this.diffToModification(repo, diff); commit.addModification(m); } } return commit; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("error detailing " + id + " in " + path, e); } }
From source file:kilim.http.HttpRequestParser.java
public static long parseDate(byte[] data, int pos, int len) { int p = 0;/* w w w. j a v a 2 s . co m*/ int pe = len; // int eof = pe; int cs; // int wkday = 0; int day = 0, month = 0, year = 0; int hh = 0, mm = 0, ss = 0; // line 1510 "HttpRequestParser.java" { cs = http_date_start; } // line 299 "HttpRequestParser.rl" // line 1517 "HttpRequestParser.java" { int _klen; int _trans = 0; int _acts; int _nacts; int _keys; int _goto_targ = 0; _goto: while (true) { switch (_goto_targ) { case 0: if (p == pe) { _goto_targ = 4; continue _goto; } if (cs == 0) { _goto_targ = 5; continue _goto; } case 1: _match: do { _keys = _http_date_key_offsets[cs]; _trans = _http_date_index_offsets[cs]; _klen = _http_date_single_lengths[cs]; if (_klen > 0) { int _lower = _keys; int _mid; int _upper = _keys + _klen - 1; while (true) { if (_upper < _lower) break; _mid = _lower + ((_upper - _lower) >> 1); if (data[p] < _http_date_trans_keys[_mid]) _upper = _mid - 1; else if (data[p] > _http_date_trans_keys[_mid]) _lower = _mid + 1; else { _trans += (_mid - _keys); break _match; } } _keys += _klen; _trans += _klen; } _klen = _http_date_range_lengths[cs]; if (_klen > 0) { int _lower = _keys; int _mid; int _upper = _keys + (_klen << 1) - 2; while (true) { if (_upper < _lower) break; _mid = _lower + (((_upper - _lower) >> 1) & ~1); if (data[p] < _http_date_trans_keys[_mid]) _upper = _mid - 2; else if (data[p] > _http_date_trans_keys[_mid + 1]) _lower = _mid + 2; else { _trans += ((_mid - _keys) >> 1); break _match; } } _trans += _klen; } } while (false); cs = _http_date_trans_targs[_trans]; if (_http_date_trans_actions[_trans] != 0) { _acts = _http_date_trans_actions[_trans]; _nacts = (int) _http_date_actions[_acts++]; while (_nacts-- > 0) { switch (_http_date_actions[_acts++]) { case 0: // line 254 "HttpRequestParser.rl" { day = day * 10 + (data[p] - 48); } break; case 1: // line 255 "HttpRequestParser.rl" { year = year * 10 + (data[p] - 48); } break; case 2: // line 256 "HttpRequestParser.rl" { hh = hh * 10 + (data[p] - 48); } break; case 3: // line 257 "HttpRequestParser.rl" { mm = mm * 10 + (data[p] - 48); } break; case 4: // line 258 "HttpRequestParser.rl" { ss = ss * 10 + (data[p] - 48); } break; case 5: // line 262 "HttpRequestParser.rl" { month = 0; } break; case 6: // line 263 "HttpRequestParser.rl" { month = 1; } break; case 7: // line 264 "HttpRequestParser.rl" { month = 2; } break; case 8: // line 265 "HttpRequestParser.rl" { month = 3; } break; case 9: // line 266 "HttpRequestParser.rl" { month = 4; } break; case 10: // line 267 "HttpRequestParser.rl" { month = 5; } break; case 11: // line 268 "HttpRequestParser.rl" { month = 6; } break; case 12: // line 269 "HttpRequestParser.rl" { month = 7; } break; case 13: // line 270 "HttpRequestParser.rl" { month = 8; } break; case 14: // line 271 "HttpRequestParser.rl" { month = 90; } break; case 15: // line 272 "HttpRequestParser.rl" { month = 10; } break; case 16: // line 273 "HttpRequestParser.rl" { month = 11; } break; // line 1664 "HttpRequestParser.java" } } } case 2: if (cs == 0) { _goto_targ = 5; continue _goto; } if (++p != pe) { _goto_targ = 1; continue _goto; } case 4: case 5: } break; } } // line 300 "HttpRequestParser.rl" if (year < 100) { year += 1900; } GregorianCalendar gc = new GregorianCalendar(); gc.set(year, month, day, hh, mm, ss); gc.setTimeZone(GMT); return gc.getTimeInMillis(); }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.AnalyzeMyDriving.java
public void sendLocation(final Location location) { if (connectDeviceClient()) { final GregorianCalendar cal = new GregorianCalendar(); final TimeZone gmt = TimeZone.getTimeZone("GMT"); cal.setTimeZone(gmt); final SimpleDateFormat formattedCal = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formattedCal.setCalendar(cal);/*from ww w . ja v a 2 s . com*/ final String timestamp = formattedCal.format(cal.getTime()); final double speed = Math.max(0.0, location.getSpeed() * 60 * 60 / 1000); final double longitude = location.getLongitude(); final double latitude = location.getLatitude(); final String mobileAppDeviceId = FirstPage.mobileAppDeviceId; final String status = tripID != null ? "Unlocked" : "Locked"; if (tripID == null) { // this trip should be completed, so lock device now userUnlocked = false; } final JsonObject event = new JsonObject(); final JsonObject data = new JsonObject(); event.add("d", data); data.addProperty("trip_id", tripID); data.addProperty("speed", speed); data.addProperty("lng", longitude); data.addProperty("lat", latitude); data.addProperty("ts", timestamp); data.addProperty("id", mobileAppDeviceId); data.addProperty("status", status); final ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (deviceClient.publishEvent("sensorData", event, 0)) { Log.d("MQTT", "publish event " + event.toString()); supportActionBar.setTitle(speedMessage + " - Data sent (" + (++transmissionCount) + ")"); } else { Log.d("MQTT", "ERROR in publishing event " + event.toString()); supportActionBar.setTitle("Data Transmission Error."); } } }