List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(int year, int monthOfYear, int dayOfMonth)
ISOChronology
. From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSCostStatsService.java
License:Open Source License
private void downloadAndParse(AWSCostStatsCreationContext statsData, String awsBucketname, int year, int month, AWSCostStatsCreationStages next) throws IOException { // Creating a working directory for downloanding and processing the bill final Path workingDirPath = Paths.get(System.getProperty(TEMP_DIR_LOCATION), UUID.randomUUID().toString()); Files.createDirectories(workingDirPath); String accountId = statsData.computeDesc.customProperties.getOrDefault(AWSConstants.AWS_ACCOUNT_ID_KEY, null);/* w w w .j a v a2 s . c o m*/ AWSCsvBillParser parser = new AWSCsvBillParser(); final String csvBillZipFileName = parser.getCsvBillFileName(month, year, accountId, true); Path csvBillZipFilePath = Paths.get(workingDirPath.toString(), csvBillZipFileName); GetObjectRequest getObjectRequest = new GetObjectRequest(awsBucketname, csvBillZipFileName); Download download = statsData.s3Client.download(getObjectRequest, csvBillZipFilePath.toFile()); final StatelessService service = this; download.addProgressListener(new ProgressListener() { @Override public void progressChanged(ProgressEvent progressEvent) { try { ProgressEventType eventType = progressEvent.getEventType(); if (ProgressEventType.TRANSFER_COMPLETED_EVENT.equals(eventType)) { LocalDate monthDate = new LocalDate(year, month, 1); statsData.accountDetailsMap = parser.parseDetailedCsvBill(statsData.ignorableInvoiceCharge, csvBillZipFilePath, monthDate); deleteTempFiles(); OperationContext.restoreOperationContext(statsData.opContext); statsData.stage = next; handleCostStatsCreationRequest(statsData); } else if (ProgressEventType.TRANSFER_FAILED_EVENT.equals(eventType)) { deleteTempFiles(); throw new IOException("Download of AWS CSV Bill '" + csvBillZipFileName + "' failed."); } } catch (IOException e) { logSevere(e); AdapterUtils.sendFailurePatchToProvisioningTask(service, statsData.statsRequest.taskReference, e); } } private void deleteTempFiles() { try { Files.deleteIfExists(csvBillZipFilePath); Files.deleteIfExists(workingDirPath); } catch (IOException e) { // Ignore IO exception while cleaning files. } } }); }
From source file:com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.java
License:Open Source License
protected void scheduleDownload(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) { AWSCsvBillParser parser = new AWSCsvBillParser(); //sample bill used is for September month of 2016. LocalDate monthDate = new LocalDate(2016, 9, 1); Path csvBillZipFilePath;//from w w w.j a v a2 s . co m try { csvBillZipFilePath = TestUtils.getTestResourcePath(TestAWSCostAdapterService.class, TestAWSSetupUtils.SAMPLE_AWS_BILL); statsData.accountDetailsMap = parser.parseDetailedCsvBill(statsData.ignorableInvoiceCharge, csvBillZipFilePath, monthDate); } catch (Throwable e) { AdapterUtils.sendFailurePatchToProvisioningTask(this, statsData.statsRequest.taskReference, new RuntimeException(e)); } statsData.stage = next; handleCostStatsCreationRequest(statsData); }
From source file:courtscheduler.persistence.CourtScheduleInfo.java
License:Apache License
public static LocalDate parseDateString(String dateString) { String[] dateComponentStrings = dateString.split("[-//]"); int[] dateComponentInts = new int[dateComponentStrings.length]; int year, month, day; if (dateComponentStrings.length != 3) { // do something else } else {//from ww w .ja va2 s . c o m dateComponentInts[0] = Integer.parseInt(dateComponentStrings[0]); dateComponentInts[1] = Integer.parseInt(dateComponentStrings[1]); dateComponentInts[2] = Integer.parseInt(dateComponentStrings[2]); day = dateComponentInts[1]; month = dateComponentInts[0]; year = dateComponentInts[2]; return new LocalDate(year, month, day); } return null; }
From source file:cz.krtinec.birthday.dto.Event.java
License:Open Source License
public Event(String displayName, long contactId, LocalDate eventDate, String lookupKey, DateIntegrity integrity, long rawContactId) { this.integrity = integrity; this.displayName = displayName; this.contactId = contactId; this.lookupKey = lookupKey; this.eventDate = eventDate; if (this.eventDate != null) { eventDaySort = SHORT_FORMAT.print(this.eventDate); } else {// w w w . ja v a 2 s .c o m eventDaySort = "0000"; } nextYear = eventDaySort.compareTo(pivot) < 0; if (this.eventDate != null) { int year = nextYear ? today.getYear() + 1 : today.getYear(); LocalDate tempCalendar; try { tempCalendar = new LocalDate(year, eventDate.getMonthOfYear(), eventDate.getDayOfMonth()); } catch (IllegalFieldValueException e) { //Probably February 29th tempCalendar = new LocalDate(year, eventDate.getMonthOfYear(), eventDate.getDayOfMonth() - 1); } daysToEvent = Days.daysBetween(today, tempCalendar).getDays(); } this.rawContactId = rawContactId; }
From source file:cz.krtinec.birthday.ui.EditActivity.java
License:Open Source License
private Dialog createEditDialog(final Context ctx) { DatePickerDialog datePicker = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() { @Override/*from w ww . ja v a2 s .c o m*/ public void onDateSet(DatePicker datePicker, int year, int month, int day) { eventToEdit.eventDate = new LocalDate(year, month + 1, day); eventToEdit.integrity = DateIntegrity.FULL; listAdapter.notifyDataSetChanged(); //enable save button if (saveButton != null) { saveButton.setEnabled(true); } } }, 2011, 0, 1); try { if (eventToEdit != null && eventToEdit.eventDate != null) { datePicker.updateDate(eventToEdit.eventDate.getYear(), eventToEdit.eventDate.getMonthOfYear() - 1, eventToEdit.eventDate.getDayOfMonth()); } } catch (IllegalArgumentException e) { //tried to set some weird date - ignore } return datePicker; }
From source file:dao.ApplicationDAO.java
public static ArrayList<Application> filterByAge(int ageFrom, int ageTo, ArrayList<Application> filteredList) { int iAge = 0; ArrayList<Application> newAppList = new ArrayList<Application>(); for (Application app : filteredList) { //get int dob from database String dateOfBirth = app.getDob(); int dobDay = Integer.parseInt(dateOfBirth.substring(0, 2)); int dobMonth = Integer.parseInt(dateOfBirth.substring(3, 5)); int dobYear = Integer.parseInt(dateOfBirth.substring(6, 10)); LocalDate dob = new LocalDate(dobYear, dobMonth, dobDay); LocalDate date = new LocalDate(); Period period = new Period(dob, date, PeriodType.yearMonthDay()); iAge = period.getYears();/* w w w .j a v a 2 s .com*/ if ((iAge >= ageFrom) && (iAge <= ageTo)) { newAppList.add(app); } } return newAppList; }