List of usage examples for org.joda.time DateTime minusHours
public DateTime minusHours(int hours)
From source file:achmad.rifai.admin.ui.pesan.Add.java
private void waktune() { org.joda.time.DateTime d1 = org.joda.time.DateTime.now(), d2; if (p != null) { if (d1.minusYears(3).isAfter(p.getWaktu())) d2 = p.getWaktu();//from www .j a v a2s. c om else d2 = d1.minusYears(3); } else d2 = d1.minusYears(3); while (!d1.isBefore(d2)) { waktu.addItem(d1); d1 = d1.minusHours(1); } if (p != null) waktu.addItem(p.getWaktu()); }
From source file:ch.imetrica.mdfaTradingStrategies.MDFAStrategyEvolution.java
public void setFilterFilesiMetrica(File file, String name, int sl, int sigFreq, int pnlFreq, double spreadFilter, int shift) { String[] tokens;// w w w . j a v a 2s. co m String strline; int i, m; int n_files = 0; ArrayList<String> params = new ArrayList<String>(); String header; try { FileInputStream fin = new FileInputStream(file); DataInputStream din = new DataInputStream(fin); BufferedReader br = new BufferedReader(new InputStreamReader(din)); //----- first get the frequencies -------------- //names = new ArrayList<String>(); while ((strline = br.readLine()) != null) { tokens = strline.split("[ ]+"); String[] liquidHour = tokens[0].split("[:]+"); String[] endHour = tokens[1].split("[:]+"); String[] startHour = tokens[3].split("[:]+"); DateTime liquidTime = new DateTime(2015, 11, 17, (new Integer(liquidHour[0])).intValue(), (new Integer(liquidHour[1])).intValue()); DateTime endTime = new DateTime(2015, 11, 17, (new Integer(endHour[0])).intValue(), (new Integer(liquidHour[1])).intValue()); DateTime startTime = new DateTime(2015, 11, 17, (new Integer(startHour[0])).intValue(), (new Integer(liquidHour[1])).intValue()); liquidTime = liquidTime.minusHours(shift); endTime = endTime.minusHours(shift); startTime = startTime.minusHours(shift); int newLiquidhour = liquidTime.getHourOfDay(); int newEndhour = endTime.getHourOfDay(); int newStarthour = startTime.getHourOfDay(); String newLiquid = "" + newLiquidhour + ":" + liquidHour[1] + ":00"; String newEnd = "" + newEndhour + ":" + liquidHour[1]; String newStart = "" + newStarthour + ":" + liquidHour[1]; strline = newLiquid + " " + newEnd + " " + tokens[2] + " " + newStart + " "; for (i = 4; i < tokens.length; i++) { strline = strline + tokens[i] + " "; } params.add(strline); n_files++; } header = "String[] " + name + "_parameters = new String[" + n_files + "];"; System.out.println(header); for (m = 0; m < n_files; m++) { System.out.println(name + "_parameters[" + m + "] = \"" + params.get(m) + pnlFreq + " " + sigFreq + " " + spreadFilter + " " + name + "-signal-" + m + "\";"); } din.close(); } catch (FileNotFoundException fe) { System.out.println("File not found..." + fe); } catch (IOException ioe) { System.out.println("IO procedure faulty..." + ioe); } }
From source file:cn.cuizuoli.appranking.util.DateUtil.java
License:Apache License
/** * minusHours/*from w ww . j a va 2s. c o m*/ * @param hour * @param hours * @return */ public static String minusHours(String hour, int hours) { DateTime datetime = fromHour(hour); return toHour(datetime.minusHours(hours)); }
From source file:com.cognitivabrasil.repositorio.services.DocumentServiceImpl.java
License:Open Source License
@Override public void deleteEmpty() { DateTime d = DateTime.now(); List<Document> docs = docRep.findByCreatedLessThanAndActiveIsFalse(d.minusHours(3)); for (Document doc : docs) { deleteFromDatabase(doc);// ww w . j av a 2 s .c o m } }
From source file:com.datastax.sampledata.CreateSSTables.java
private static Date randomDateInLastNYears(int years) { DateTime dateTime = new DateTime(); dateTime = dateTime.minusYears(new Double(Math.random() * years).intValue()); dateTime = dateTime.minusMonths(new Double(Math.random() * 12).intValue()); dateTime = dateTime.minusDays(new Double(Math.random() * 30).intValue()); dateTime = dateTime.minusHours(new Double(Math.random() * 24).intValue()); dateTime = dateTime.minusMinutes(new Double(Math.random() * 60).intValue()); dateTime = dateTime.minusSeconds(new Double(Math.random() * 60).intValue()); return dateTime.toDate(); }
From source file:com.ehdev.chronos.lib.Chronos.java
License:Open Source License
public void dropAndTest() { try {/* w ww . j a v a 2s . c o m*/ // instantiate the DAO to handle Account with String id Dao<Punch, String> punchDao = getPunchDao(); Dao<Task, String> taskDAO = getTaskDao(); Dao<Job, String> jobDAO = getJobDao(); Dao<Note, String> noteDAO = getNoteDao(); List<Task> tasks = taskDAO.queryForAll(); Job currentJob = jobDAO.queryForAll().get(0); DateTime iTime = new DateTime(); Random rand = new Random(); DateTime tempTime = null; for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { tempTime = iTime.minusHours(j); tempTime = tempTime.minusMinutes(rand.nextInt() % 60); Punch temp = new Punch(currentJob, tasks.get(0), tempTime); Note newNote = new Note(tempTime, currentJob, "Note number " + String.valueOf(j + 1)); noteDAO.create(newNote); punchDao.create(temp); } tempTime = tempTime.minusMinutes(rand.nextInt() % 60); punchDao.create( new Punch(currentJob, tasks.get((int) (Math.random() * 100) % tasks.size()), tempTime)); iTime = iTime.plusDays(1); } } catch (SQLException e) { Log.e(TAG, e.getMessage()); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public static Assertion createAssertion(String username, String role, String organization, String organizationId, String facilityType, String purposeOfUse, String xspaLocality, java.util.Vector permissions) { // assertion//from w ww . j a v a 2 s .c om Assertion assertion = null; try { DefaultBootstrap.bootstrap(); XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); SAMLObjectBuilder<Assertion> builder = (SAMLObjectBuilder<Assertion>) builderFactory .getBuilder(Assertion.DEFAULT_ELEMENT_NAME); // Create the NameIdentifier SAMLObjectBuilder nameIdBuilder = (SAMLObjectBuilder) builderFactory .getBuilder(NameID.DEFAULT_ELEMENT_NAME); NameID nameId = (NameID) nameIdBuilder.buildObject(); nameId.setValue(username); //nameId.setNameQualifier(strNameQualifier); nameId.setFormat(NameID.UNSPECIFIED); assertion = create(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME); String assId = "_" + UUID.randomUUID(); assertion.setID(assId); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(new org.joda.time.DateTime().minusHours(3)); Subject subject = create(Subject.class, Subject.DEFAULT_ELEMENT_NAME); assertion.setSubject(subject); subject.setNameID(nameId); //Create and add Subject Confirmation SubjectConfirmation subjectConf = create(SubjectConfirmation.class, SubjectConfirmation.DEFAULT_ELEMENT_NAME); subjectConf.setMethod(SubjectConfirmation.METHOD_SENDER_VOUCHES); assertion.getSubject().getSubjectConfirmations().add(subjectConf); //Create and add conditions Conditions conditions = create(Conditions.class, Conditions.DEFAULT_ELEMENT_NAME); org.joda.time.DateTime now = new org.joda.time.DateTime(); conditions.setNotBefore(now.minusMinutes(1)); conditions.setNotOnOrAfter(now.plusHours(2)); // According to Spec assertion.setConditions(conditions); // AudienceRestriction ar = create(AudienceRestriction.class,AudienceRestriction.DEFAULT_ELEMENT_NAME); // Audience aud = create(Audience.class,Audience.DEFAULT_ELEMENT_NAME); // aud.setAudienceURI("aaa"); // conditions.s Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue("urn:idp:countryB"); issuer.setNameQualifier("urn:epsos:wp34:assertions"); assertion.setIssuer(issuer); //Add and create the authentication statement AuthnStatement authStmt = create(AuthnStatement.class, AuthnStatement.DEFAULT_ELEMENT_NAME); authStmt.setAuthnInstant(now.minusHours(2)); assertion.getAuthnStatements().add(authStmt); //Create and add AuthnContext AuthnContext ac = create(AuthnContext.class, AuthnContext.DEFAULT_ELEMENT_NAME); AuthnContextClassRef accr = create(AuthnContextClassRef.class, AuthnContextClassRef.DEFAULT_ELEMENT_NAME); accr.setAuthnContextClassRef(AuthnContext.PASSWORD_AUTHN_CTX); ac.setAuthnContextClassRef(accr); authStmt.setAuthnContext(ac); AttributeStatement attrStmt = create(AttributeStatement.class, AttributeStatement.DEFAULT_ELEMENT_NAME); // XSPA Subject Attribute attrPID = createAttribute(builderFactory, "XSPA subject", "urn:oasis:names:tc:xacml:1.0:subject:subject-id", username, "", ""); attrStmt.getAttributes().add(attrPID); // XSPA Role Attribute attrPID_1 = createAttribute(builderFactory, "XSPA role", "urn:oasis:names:tc:xacml:2.0:subject:role", role, "", ""); attrStmt.getAttributes().add(attrPID_1); // HITSP Clinical Speciality /* Attribute attrPID_2 = createAttribute(builderFactory,"HITSP Clinical Speciality", "urn:epsos:names:wp3.4:subject:clinical-speciality",role,"",""); attrStmt.getAttributes().add(attrPID_2); */ // XSPA Organization Attribute attrPID_3 = createAttribute(builderFactory, "XSPA Organization", "urn:oasis:names:tc:xspa:1.0:subject:organization", organization, "", ""); attrStmt.getAttributes().add(attrPID_3); // XSPA Organization ID Attribute attrPID_4 = createAttribute(builderFactory, "XSPA Organization ID", "urn:oasis:names:tc:xspa:1.0:subject:organization-id", organizationId, "AA", ""); attrStmt.getAttributes().add(attrPID_4); // // On behalf of // Attribute attrPID_4 = createAttribute(builderFactory,"OnBehalfOf", // "urn:epsos:names:wp3.4:subject:on-behalf-of",organizationId,role,""); // attrStmt.getAttributes().add(attrPID_4); // epSOS Healthcare Facility Type Attribute attrPID_5 = createAttribute(builderFactory, "epSOS Healthcare Facility Type", "urn:epsos:names:wp3.4:subject:healthcare-facility-type", facilityType, "", ""); attrStmt.getAttributes().add(attrPID_5); // XSPA Purpose of Use Attribute attrPID_6 = createAttribute(builderFactory, "XSPA Purpose Of Use", "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse", purposeOfUse, "", ""); attrStmt.getAttributes().add(attrPID_6); // XSPA Locality Attribute attrPID_7 = createAttribute(builderFactory, "XSPA Locality", "urn:oasis:names:tc:xspa:1.0:environment:locality", xspaLocality, "", ""); attrStmt.getAttributes().add(attrPID_7); // HL7 Permissions Attribute attrPID_8 = createAttribute(builderFactory, "Hl7 Permissions", "urn:oasis:names:tc:xspa:1.0:subject:hl7:permission"); Iterator itr = permissions.iterator(); while (itr.hasNext()) { attrPID_8 = AddAttributeValue(builderFactory, attrPID_8, itr.next().toString(), "", ""); } attrStmt.getAttributes().add(attrPID_8); assertion.getStatements().add(attrStmt); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return assertion; }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
public static Assertion createTRCAWithRef(String email, EhrPatientClientDto patient, String purposeOfUse, String refAssertionId) throws ConfigurationException { // assertion/*from w w w .j a v a2s . com*/ DefaultBootstrap.bootstrap(); XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); SAMLObjectBuilder<Assertion> builder = (SAMLObjectBuilder<Assertion>) builderFactory .getBuilder(Assertion.DEFAULT_ELEMENT_NAME); // Create the NameIdentifier SAMLObjectBuilder nameIdBuilder = (SAMLObjectBuilder) builderFactory .getBuilder(NameID.DEFAULT_ELEMENT_NAME); NameID nameId = (NameID) nameIdBuilder.buildObject(); nameId.setValue(email); nameId.setFormat(NameID.EMAIL); Assertion assertion = create(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME); assertion.setID("_" + UUID.randomUUID()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(new org.joda.time.DateTime().minusHours(3)); Subject subject = create(Subject.class, Subject.DEFAULT_ELEMENT_NAME); assertion.setSubject(subject); subject.setNameID(nameId); //Create and add Subject Confirmation SubjectConfirmation subjectConf = create(SubjectConfirmation.class, SubjectConfirmation.DEFAULT_ELEMENT_NAME); subjectConf.setMethod(SubjectConfirmation.METHOD_SENDER_VOUCHES); assertion.getSubject().getSubjectConfirmations().add(subjectConf); String refAssId = refAssertionId; // Advice //Create and add Advice Advice advice = create(Advice.class, Advice.DEFAULT_ELEMENT_NAME); assertion.setAdvice(advice); //Create and add AssertionIDRef AssertionIDRef aIdRef = create(AssertionIDRef.class, AssertionIDRef.DEFAULT_ELEMENT_NAME); aIdRef.setAssertionID(refAssId); advice.getAssertionIDReferences().add(aIdRef); //Advice advice = create(Advice.class,Advice.DEFAULT_ELEMENT_NAME); //AssertionIDReference air = create(AssertionIDReference.class,AssertionIDReference.DEFAULT_ELEMENT_NAME); //air.setReference(refAssId); //advice.getAssertionIDReferences().add(air); //assertion.setAdvice(advice); //Create and add conditions Conditions conditions = create(Conditions.class, Conditions.DEFAULT_ELEMENT_NAME); org.joda.time.DateTime now = new org.joda.time.DateTime(); conditions.setNotBefore(now.minusHours(4)); conditions.setNotOnOrAfter(now.plusDays(1)); // According to Spec assertion.setConditions(conditions); Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue("urn:idp:countryB"); issuer.setNameQualifier("urn:epsos:wp34:assertions"); assertion.setIssuer(issuer); //Add and create the authentication statement AuthnStatement authStmt = create(AuthnStatement.class, AuthnStatement.DEFAULT_ELEMENT_NAME); authStmt.setAuthnInstant(now.minusHours(1)); assertion.getAuthnStatements().add(authStmt); //Create and add AuthnContext AuthnContext ac = create(AuthnContext.class, AuthnContext.DEFAULT_ELEMENT_NAME); AuthnContextClassRef accr = create(AuthnContextClassRef.class, AuthnContextClassRef.DEFAULT_ELEMENT_NAME); accr.setAuthnContextClassRef(AuthnContext.PREVIOUS_SESSION_AUTHN_CTX); ac.setAuthnContextClassRef(accr); authStmt.setAuthnContext(ac); AttributeStatement attrStmt = create(AttributeStatement.class, AttributeStatement.DEFAULT_ELEMENT_NAME); String pat = patient.getPid().get(0).getPatientID() + "^^^&" + patient.getPid().get(0).getDomain().getAuthUniversalID() + "&" + patient.getPid().get(0).getDomain().getAuthUniversalIDType(); // XSPA Subject Attribute attrPID = createAttribute(builderFactory, "XSPA subject", "urn:oasis:names:tc:xacml:1.0:resource:resource-id", pat, "", ""); attrStmt.getAttributes().add(attrPID); // XSPA Purpose of Use Attribute attrPID_6 = createAttribute(builderFactory, "XSPA Purpose Of Use", "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse", purposeOfUse, "", ""); attrStmt.getAttributes().add(attrPID_6); assertion.getStatements().add(attrStmt); return assertion; }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeUtil.java
License:Apache License
public static DateTime normalize(DateTime dateTime) { if (dateTime.toString().matches(".+(\\+)[0-9][0-9]:[0-9][0-9]")) { dateTime = dateTime.minusHours(dateTime.getHourOfDay()); } else if (dateTime.toString().matches(".+(\\-)[0-9][0-9]:[0-9][0-9]")) { dateTime = dateTime.plusHours(24 - dateTime.getHourOfDay()); }//from www . ja v a 2 s.c o m return dateTime; }
From source file:com.linkedin.cubert.utils.FileSystemUtils.java
License:Open Source License
public static List<Path> getDurationPaths(FileSystem fs, Path root, DateTime startDate, DateTime endDate, boolean isDaily, int hourStep, boolean errorOnMissing, boolean useHourlyForMissingDaily) throws IOException { List<Path> paths = new ArrayList<Path>(); while (endDate.compareTo(startDate) >= 0) { Path loc;/*from www. j a va 2 s . com*/ if (isDaily) loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth()); else loc = generateDatedPath(root, endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth(), endDate.getHourOfDay()); // Check that directory exists, and contains avro files. if (fs.exists(loc) && fs.globStatus(new Path(loc, "*" + "avro")).length > 0) { paths.add(loc); } else { loc = generateDatedPath(new Path(root.getParent(), "hourly"), endDate.getYear(), endDate.getMonthOfYear(), endDate.getDayOfMonth()); if (isDaily && useHourlyForMissingDaily && fs.exists(loc)) { for (FileStatus hour : fs.listStatus(loc)) { paths.add(hour.getPath()); } } else if (errorOnMissing) { throw new RuntimeException("Missing directory " + loc.toString()); } } if (hourStep == 24) endDate = endDate.minusDays(1); else endDate = endDate.minusHours(hourStep); } return paths; }