List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:uk.nhs.cfh.dsp.srth.demographics.person.utils.PatientUtilsServiceImpl.java
public Calendar getRandomDateInTimeRangeInFuture(Calendar anchor, int yearUpperBound, int yearLowerBound, int monthUpperBound, int monthLowerBound, int dayUpperBound, int dayLowerBound) { int randomYear = (int) (Math.random() * (yearUpperBound - yearLowerBound)) + yearLowerBound; int randomMonth = (int) (Math.random() * (monthUpperBound - monthLowerBound)) + monthLowerBound; int randomDay = (int) (Math.random() * (dayUpperBound - dayLowerBound)) + dayLowerBound; // forward calendar by year and month GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(anchor.getTime());// w ww. j a v a2 s .c om calendar.add(Calendar.YEAR, randomYear); calendar.add(Calendar.MONTH, randomMonth); calendar.add(Calendar.DATE, randomDay); logger.debug("Value of calendar.get(year) : " + calendar.get(Calendar.YEAR)); return calendar; }
From source file:ejava.projects.edmv.bl.DataGen.java
protected ResidenceType createXMLResidence(DMVResidence residence) { ResidenceType xmlResidence = new ResidenceType(); xmlResidence.setResidenceStartDate(new Date()); xmlResidence.setResidenceEndDate(new Date()); GregorianCalendar gDate = new GregorianCalendar(); XMLGregorianCalendar xDate = dtf.newXMLGregorianCalendar(); if (residence.getStartDate() != null) { gDate.setTime(residence.getStartDate()); xDate.setYear(gDate.get(GregorianCalendar.YEAR)); xDate.setMonth(gDate.get(GregorianCalendar.MONTH) + 1); xDate.setDay(gDate.get(GregorianCalendar.DAY_OF_MONTH)); xmlResidence.getResidenceStartDate().setValue(xDate); }/*w ww.jav a 2 s . com*/ if (residence.getEndDate() != null) { gDate.setTime(residence.getEndDate()); xDate.setYear(gDate.get(GregorianCalendar.YEAR)); xDate.setMonth(gDate.get(GregorianCalendar.MONTH) + 1); xDate.setDay(gDate.get(GregorianCalendar.DAY_OF_MONTH)); xmlResidence.getResidenceEndDate().setValue(xDate); } if (residence.getLocation() != null) { AddressType address = new AddressType(); address.setLocationStreet(new StreetType()); address.getLocationStreet().setStreetNumberText(new TextType()); address.getLocationStreet().setStreetName(new TextType()); address.setLocationCityName(new TextType()); address.setLocationStateCodeUSPostalService(new USStateCodeType()); address.setLocationPostalCodeID(new IDType()); address.getLocationPostalCodeID().setID(new TextType()); address.getLocationStreet().getStreetNumberText() .setValue(residence.getLocation().getStreetNumber().trim()); address.getLocationStreet().getStreetName().setValue(residence.getLocation().getStreetName().trim()); address.getLocationCityName().setValue(residence.getLocation().getCityName().trim()); address.getLocationStateCodeUSPostalService().setValue(residence.getLocation().getState().trim()); address.getLocationPostalCodeID().getID().setValue(residence.getLocation().getZip().trim()); xmlResidence.setLocationAddress(address); } return xmlResidence; }
From source file:com.jfootball.dao.hibernate.PlayerDaoImpl.java
public void endSeasonJob() { logger.info("Execute endSeason job"); Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory(); try {/*from w w w .j a v a2 s .c om*/ Connection conn = sessionFactory.getConnectionProvider().getConnection(); CallableStatement cstmt = conn.prepareCall("{ call endSeasonBatch(?) }"); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(new Date(System.currentTimeMillis())); int year = gc.get(Calendar.YEAR); cstmt.setString("param_year", "30/06/" + year); // current year. cstmt.execute(); logger.info("EndSeason job executed"); } catch (SQLException e) { logger.error(e); } logger.info("EndSeason job finished"); }
From source file:com.googlecode.networklog.ExportDialog.java
public ExportDialog(final Context context) { this.context = context; Resources res = context.getResources(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.exportdialog, null); startDateButton = (Button) view.findViewById(R.id.exportStartDateButton); endDateButton = (Button) view.findViewById(R.id.exportEndDateButton); filenameButton = (Button) view.findViewById(R.id.exportFilenameButton); GregorianCalendar today = new GregorianCalendar(); startDate = new GregorianCalendar(today.get(Calendar.YEAR), today.get(Calendar.MONTH), 1).getTime(); endDate = today.getTime();/*from w w w . j a v a 2 s. c o m*/ file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + defaultFilename()); startDateButton.setText(dateDisplayFormat.format(startDate)); endDateButton.setText(dateDisplayFormat.format(endDate)); filenameButton.setText(file.getAbsolutePath()); startDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { datePickerMode = DatePickerMode.START_DATE; DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { startDate = new GregorianCalendar(year, month, day).getTime(); startDateButton.setText(dateDisplayFormat.format(startDate)); updateFilename(); } }; Calendar cal = Calendar.getInstance(); cal.setTime(startDate); DialogFragment newFragment = new DatePickerFragment(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), listener); newFragment.show(NetworkLog.instance.getSupportFragmentManager(), "exportDatePicker"); } }); endDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { datePickerMode = DatePickerMode.END_DATE; DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int month, int day) { endDate = new GregorianCalendar(year, month, day, 23, 59, 59).getTime(); endDateButton.setText(dateDisplayFormat.format(endDate)); updateFilename(); } }; Calendar cal = Calendar.getInstance(); cal.setTime(endDate); DialogFragment newFragment = new DatePickerFragment(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), listener); newFragment.show(NetworkLog.instance.getSupportFragmentManager(), "exportDatePicker"); } }); filenameButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { OnHandleFileListener saveListener = new OnHandleFileListener() { public void handleFile(final String filePath) { file = new File(filePath); filenameButton.setText(filePath); } }; new FileSelector(context, FileOperation.SAVE, saveListener, defaultFilename(), new String[] { "*.*", "*.csv" }).show(); } }); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(res.getString(R.string.export_title)).setView(view).setCancelable(true) .setPositiveButton(res.getString(R.string.export_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int id) { // see show() method for implementation -- avoids dismiss() unless validation passes } }).setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int id) { dialog.cancel(); dialog = null; } }); dialog = builder.create(); }
From source file:com.liferay.faces.generator.Generator.java
private void generateComponents(String tagsFilePath) throws FileNotFoundException, IOException { File file = new File(tagsFilePath); if (!file.exists()) { throw new FileNotFoundException(tagsFilePath + " not found."); }//from w ww . ja va 2s.c o m if (!file.isFile()) { throw new IllegalArgumentException(tagsFilePath + " is not a file."); } if (!file.canRead()) { throw new IllegalArgumentException(tagsFilePath + " is not a readable file."); } String fileName = file.getName(); String shortNamespace = fileName.replace("-tags.xml", ""); Map<String, Object> freemarkerProperties = new HashMap<String, Object>(); freemarkerProperties.put("shortNamespace", shortNamespace); Document document = null; try { document = documentBuilder.parse(file); } catch (SAXException e) { throw new IllegalArgumentException(tagsFilePath + " is not a valid xml file.", e); } Map<String, Tag> tagMap = new HashMap<String, Tag>(); tagMap.putAll(commonComponentsMap); boolean taglibExtensionElementExists = false; String componentOutpoutDirectoryPath = null; String componentInternalOutpoutDirectoryPath = null; String taglibXMLOuputDirectoryPath = null; Node documentNode = document.getDocumentElement(); NodeList childNodes = documentNode.getChildNodes(); int totalChildNodes = childNodes.getLength(); for (int i = 0; i < totalChildNodes; i++) { Node childNode = childNodes.item(i); String nodeName = childNode.getNodeName(); if (nodeName.equals("tag")) { Tag tag = new Tag(childNode); tagMap.put(tag.getTagName(), tag); } else if (nodeName.equals("taglib-extension")) { taglibExtensionElementExists = true; componentOutpoutDirectoryPath = GeneratorUtil.getNodeContents("component-output-directory", childNode); if ((componentOutpoutDirectoryPath == null) || componentOutpoutDirectoryPath.equals("")) { throw new NullPointerException("<component-output-directory> must be specified."); } componentInternalOutpoutDirectoryPath = GeneratorUtil .getNodeContents("component-internal-output-directory", childNode); if ((componentInternalOutpoutDirectoryPath == null) || componentInternalOutpoutDirectoryPath.equals("")) { componentInternalOutpoutDirectoryPath = componentOutpoutDirectoryPath; } taglibXMLOuputDirectoryPath = GeneratorUtil.getNodeContents("taglib-xml-output-directory", childNode); if ((taglibXMLOuputDirectoryPath == null) || taglibXMLOuputDirectoryPath.equals("")) { throw new NullPointerException("<taglib-xml-output-directory> must be specified."); } String authorsString = GeneratorUtil.getNodeContents("authors", childNode); if ((authorsString != null) && !authorsString.equals("")) { String[] authorsArray = authorsString.split(","); List<String> authors = new ArrayList<String>(); for (String author : authorsArray) { String trimmedAuthor = author.trim(); authors.add(trimmedAuthor); } if (!authors.isEmpty()) { freemarkerProperties.put("authors", authors); } } String copyrightYear = GeneratorUtil.getNodeContents("copyright-year", childNode); if ((copyrightYear == null) || copyrightYear.equals("")) { GregorianCalendar calendar = new GregorianCalendar(); int year = calendar.get(Calendar.YEAR); copyrightYear = String.valueOf(year); } freemarkerProperties.put("copyrightYear", copyrightYear); String defaultSince = GeneratorUtil.getNodeContents("default-since", childNode); if (defaultSince == null) { defaultSince = "1.0.0"; } freemarkerProperties.put("defaultSince", defaultSince); String facesSpecVersion = GeneratorUtil.getNodeContents("faces-spec-version", childNode); if ((facesSpecVersion == null) || facesSpecVersion.equals("")) { facesSpecVersion = "2.0"; } freemarkerProperties.put("facesSpecVersion", facesSpecVersion); } } if (!taglibExtensionElementExists) { throw new NullPointerException("<taglib-extension> must be specified."); } Set<Entry<String, Tag>> tagMapEntrySet = tagMap.entrySet(); for (Entry<String, Tag> tagEntry : tagMapEntrySet) { Tag tag = (Tag) tagEntry.getValue(); addExtensionAttributes(tag, tagMap, document); if (tag.isGenerateJava() && (tag.isGenerateComponent() || tag.isGenerateRenderer())) { NodeModel tagNodeModel = tag.getTagNodeModel(); freemarkerProperties.put("tag", tagNodeModel); if (tag.isGenerateComponent()) { generateComponentFile(componentOutpoutDirectoryPath, shortNamespace, tag, "Component", freemarkerProperties); generateComponentFile(componentOutpoutDirectoryPath, shortNamespace, tag, "ComponentBase", freemarkerProperties); } if (tag.isGenerateRenderer()) { generateComponentFile(componentInternalOutpoutDirectoryPath, shortNamespace, tag, "ComponentRenderer", freemarkerProperties); generateComponentFile(componentInternalOutpoutDirectoryPath, shortNamespace, tag, "ComponentRendererBase", freemarkerProperties); } } } freemarkerProperties.remove("tag"); NodeModel tagsDocumentNodeModel = NodeModel.wrap(document); freemarkerProperties.put("tagsDocument", tagsDocumentNodeModel); StringBuilder taglibXMLFilePathStringBuilder = new StringBuilder(); taglibXMLFilePathStringBuilder.append(taglibXMLOuputDirectoryPath); taglibXMLFilePathStringBuilder.append("/"); taglibXMLFilePathStringBuilder.append(shortNamespace); taglibXMLFilePathStringBuilder.append(".taglib.xml"); generateFile(taglibXMLFilePathStringBuilder.toString(), freemarkerProperties, "taglib.xml.ftl", true); }
From source file:org.apache.eagle.jpm.mr.history.crawler.JHFCrawlerDriverImpl.java
private void readAndCacheLastProcessedDate() throws Exception { String lastProcessedDate = JobHistoryZKStateManager.instance().readProcessedDate(partitionId); Matcher m = PATTERN_JOB_PROCESS_DATE.matcher(lastProcessedDate); if (m.find() && m.groupCount() == 3) { this.processDate.year = Integer.parseInt(m.group(1)); this.processDate.month = Integer.parseInt(m.group(2)) - 1; // zero based month this.processDate.day = Integer.parseInt(m.group(3)); } else {//from ww w . ja v a2 s. c o m throw new IllegalStateException("job lastProcessedDate must have format YYYYMMDD " + lastProcessedDate); } GregorianCalendar cal = new GregorianCalendar(timeZone); cal.set(this.processDate.year, this.processDate.month, this.processDate.day, 0, 0, 0); cal.add(Calendar.DATE, 1); List<String> list = JobHistoryZKStateManager.instance() .readProcessedJobs(String.format(FORMAT_JOB_PROCESS_DATE, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))); if (list != null) { this.processedJobFileNames = new HashSet<>(list); } }
From source file:uk.nhs.cfh.dsp.srth.demographics.person.utils.PatientUtilsServiceImpl.java
public Calendar getRandomDateInTimeRange(Calendar anchor, int yearUpperBound, int yearLowerBound, int monthUpperBound, int monthLowerBound, int dayUpperBound, int dayLowerBound) { int randomYear = (int) (Math.random() * (yearUpperBound - yearLowerBound)) + yearLowerBound; int randomMonth = (int) (Math.random() * (monthUpperBound - monthLowerBound)) + monthLowerBound; int randomDay = (int) (Math.random() * (dayUpperBound - dayLowerBound)) + dayLowerBound; // debugging output if (logger.isDebugEnabled()) { logger.debug("Value of anchor year: " + anchor.get(Calendar.YEAR)); logger.debug("Value of anchor month: " + anchor.get(Calendar.MONTH)); logger.debug("Value of anchor date: " + anchor.get(Calendar.DATE)); logger.debug("Value of randomYear : " + randomYear); logger.debug("Value of randomMonth : " + randomMonth); logger.debug("Value of randomDay : " + randomDay); }/*from w w w .j a v a2 s .c om*/ // forward calendar by year and month GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(anchor.getTime()); calendar.add(Calendar.YEAR, -randomYear); calendar.add(Calendar.MONTH, -randomMonth); calendar.add(Calendar.DATE, -randomDay); if (logger.isDebugEnabled()) { logger.debug("Value of calendar.get(year) : " + calendar.get(Calendar.YEAR)); } return calendar; }
From source file:net.naijatek.myalumni.util.taglib.BuildDropdownTag.java
protected String renderYearInDropDown() { int startYear = systemConfigService.getFirstYearofSchool(); // Integer.parseInt(sysProp.getValue("years.start")); GregorianCalendar ct = new GregorianCalendar(); int currentYear = ct.get(Calendar.YEAR); StringBuffer sb = new StringBuffer(); sb.append("<option value=\"\">-- Select --</option>"); for (int i = currentYear; i > startYear - 1; i--) { sb.append("<option value=\""); sb.append(String.valueOf(i)); sb.append("\""); if (getData() != null && getData().trim().length() > 0 && getData().equals(String.valueOf(i))) { sb.append(" selected"); }/*from ww w .j a va 2 s . c o m*/ sb.append(">"); sb.append(String.valueOf(i)); sb.append("</option>"); } return sb.toString(); }
From source file:net.naijatek.myalumni.util.taglib.BuildDropdownTag.java
protected String renderClassYearDropDown() { int startYear = systemConfigService.getFirstYearofSchool(); // Integer.parseInt(sysProp.getValue("years.start")); GregorianCalendar ct = new GregorianCalendar(); int currentYear = ct.get(Calendar.YEAR); StringBuffer sb = new StringBuffer(); sb.append("<option value=\"\">-- Select --</option>"); for (int i = currentYear; i > startYear - 1; i--) { sb.append("<option value=\""); sb.append(String.valueOf(i)); sb.append("\""); if (getData() != null && getData().trim().length() > 0 && getData().equals(String.valueOf(i))) { sb.append(" selected"); }// ww w.j a v a 2 s . co m sb.append(">"); sb.append(String.valueOf(i)); sb.append("</option>"); } return sb.toString(); }
From source file:net.naijatek.myalumni.util.taglib.BuildDropdownTag.java
protected String renderYearOutDropDown() { int startYear = systemConfigService.getFirstYearofSchool(); // Integer.parseInt(sysProp.getValue("years.start")); GregorianCalendar ct = new GregorianCalendar(); int currentYear = ct.get(Calendar.YEAR); StringBuffer sb = new StringBuffer(); sb.append("<option value=\"\">-- Select --</option>"); for (int i = currentYear + 6; i > startYear - 1; i--) { // 6 year after year in will give us year out, why 6, i dont know, sound resonable sb.append("<option value=\""); sb.append(String.valueOf(i)); sb.append("\""); if (getData() != null && getData().trim().length() > 0 && getData().equals(String.valueOf(i))) { sb.append(" selected"); }/* ww w.j a v a 2s . c o m*/ sb.append(">"); sb.append(String.valueOf(i)); sb.append("</option>"); } return sb.toString(); }