List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java
License:Open Source License
private Header createSAFTHeader(DateTime startDate, DateTime endDate, FinantialInstitution finantialInstitution, String auditVersion) {/*from ww w.ja v a2 s. c o m*/ Header header = new Header(); DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); // AuditFileVersion header.setAuditFileVersion(auditVersion); // BusinessName - Nome da Empresa header.setBusinessName(finantialInstitution.getCompanyName()); header.setCompanyName(finantialInstitution.getName()); // CompanyAddress AddressStructurePT companyAddress = null; //TODOJN Locale por resolver companyAddress = convertAddressToAddressPT(finantialInstitution.getAddress(), finantialInstitution.getZipCode(), finantialInstitution.getMunicipality() != null ? finantialInstitution.getMunicipality().getLocalizedName(new Locale("pt")) : "---", finantialInstitution.getAddress()); header.setCompanyAddress(companyAddress); // CompanyID /* * Obtem -se pela concatena??o da conservat?ria do registo comercial * com o n?mero do registo comercial, separados pelo car?cter * espa?o. Nos casos em que n?o existe o registo comercial, deve ser * indicado o NIF. */ header.setCompanyID(finantialInstitution.getComercialRegistrationCode()); // CurrencyCode /* * 1.11 * C?digo de moeda (CurrencyCode) . . . . . . . Preencher com * ?EUR? */ header.setCurrencyCode(finantialInstitution.getCurrency().getCode()); // DateCreated DateTime now = new DateTime(); header.setDateCreated(convertToXMLDateTime(dataTypeFactory, now)); // Email // header.setEmail(StringUtils.EMPTY); // EndDate header.setEndDate(convertToXMLDateTime(dataTypeFactory, endDate)); // Fax // header.setFax(StringUtils.EMPTY); // FiscalYear /* * Utilizar as regras do c?digo do IRC, no caso de per?odos * contabil?sticos n?o coincidentes com o ano civil. (Ex: per?odo de * tributa??o de 01 -10 -2008 a 30 -09 -2009 corresponde FiscalYear * 2008). Inteiro 4 */ header.setFiscalYear(endDate.getYear()); // Ir obter a data do ?ltimo // documento(por causa de submeter em janeiro, documentos de // dezembro) // HeaderComment // header.setHeaderComment(org.apache.commons.lang.StringUtils.EMPTY); // ProductCompanyTaxID // Preencher com o NIF da entidade produtora do software header.setProductCompanyTaxID(SaftConfig.PRODUCT_COMPANY_TAX_ID()); // ProductID /* * 1.16 * Nome do produto (ProductID). . . . . . . . . . . Nome do * produto que gera o SAF -T (PT) . . . . . . . . . . . Deve ser * indicado o nome comercial do software e o da empresa produtora no * formato ?Nome produto/nome empresa?. */ header.setProductID(SaftConfig.PRODUCT_ID()); // Product Version header.setProductVersion(SaftConfig.PRODUCT_VERSION()); // SoftwareCertificateNumber header.setSoftwareCertificateNumber(BigInteger.valueOf(SaftConfig.SOFTWARE_CERTIFICATE_NUMBER())); // StartDate header.setStartDate(dataTypeFactory.newXMLGregorianCalendarDate(startDate.getYear(), startDate.getMonthOfYear(), startDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED)); // TaxAccountingBasis /* * Deve ser preenchido com: contabilidade; facturao; ?I? ? dados * integrados de factura??o e contabilidade; ?S? ? autofactura??o; * ?P? ? dados parciais de factura??o */ header.setTaxAccountingBasis("P"); // TaxEntity /* * Identifica??o do estabelecimento (TaxEntity) No caso do ficheiro * de factura??o dever? ser especificado a que estabelecimento diz * respeito o ficheiro produzido, se aplic?vel, caso contr?rio, * dever? ser preenchido com a especifica??o ?Global?. No caso do * ficheiro de contabilidade ou integrado, este campo dever? ser * preenchido com a especifica??o ?Sede?. Texto 20 */ header.setTaxEntity("Global"); // TaxRegistrationNumber /* * N?mero de identifica??o fiscal da empresa * (TaxRegistrationNumber). Preencher com o NIF portugu?s sem * espa?os e sem qualquer prefixo do pa?s. Inteiro 9 */ try { header.setTaxRegistrationNumber(Integer.parseInt(finantialInstitution.getFiscalNumber())); } catch (Exception ex) { throw new RuntimeException("Invalid Fiscal Number."); } // header.setTelephone(finantialInstitution.get); // header.setWebsite(finantialInstitution.getEmailContact()); return header; } catch (DatatypeConfigurationException e) { e.printStackTrace(); return null; } }
From source file:org.forgerock.openidm.util.DateUtil.java
License:CDDL license
/** * Returns a {@link String} representing a scheduler expression of the supplied date. The scheduler expression is of * the form: "{second} {minute} {hour} {day} {month} ? {year}". * * For example, a scheduler expression for January 3, 2016 at 04:56 AM would be: "0 56 4 3 1 ? 2016". * // ww w. java2s . c o m * @param intervalString a {@link String} object representing an ISO 8601 time interval. * @return a {@link String} representing a scheduler expression of the supplied date. * @throws IllegalArgumentException if an error occurs while parsing the intervalString. */ public String getSchedulerExpression(DateTime date) throws IllegalArgumentException { StringBuilder sb = new StringBuilder().append(date.getSecondOfMinute()).append(" ") .append(date.getMinuteOfHour()).append(" ").append(date.getHourOfDay()).append(" ") .append(date.getDayOfMonth()).append(" ").append(date.getMonthOfYear()).append(" ").append("? ") .append(date.getYear()); return sb.toString(); }
From source file:org.gephi.desktop.timeline.MinimalDrawer.java
License:Open Source License
private void paintUpperRulerForInterval(Graphics2D g2d, DateTime dtFrom, DateTime dtTo) { g2d.setFont(settings.graduations.font); g2d.setColor(settings.graduations.fontColor); int leftMargin = settings.graduations.leftMargin; int textTopPosition = settings.graduations.textTopPosition; int width = getWidth(); int height = getHeight(); // TODO take these from the model Interval interval = new Interval(dtFrom, dtTo); Period p = interval.toPeriod(PeriodType.days()); // try to determine length if we had to show milliseconds int n = p.getDays(); int unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wednesday ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jour"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition);/*from ww w . j a va 2 s . co m*/ g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wed ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jou"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.days()); n = p.getDays(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("30", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("j"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getDayOfMonth() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.months()); n = p.getMonths(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("September ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mois"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("dec ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mo"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("29 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("m"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getMonthOfYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } p = interval.toPeriod(PeriodType.years()); n = p.getYears(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("1980 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("year"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months.monthsBetween(dtFrom.plusYears(i), dtFrom.plusYears(i + 1)).getMonths()); } return; } int group = 10; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("10 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 20; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("20 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 50; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("50 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 100; n = p.getYears() / group; if (n / 100 < (width / unitSize)) { //System.out.println("100 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } } return; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static int getEasterEggTitleColor() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return 0xFF5E00; //orange }//from w ww .ja v a2 s . c om return -1; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static String getSplashTextEasterEgg() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return "Happy Halloween!"; }// w w w.j av a 2s . c o m return null; }
From source file:org.getspout.spout.EasterEggs.java
License:Open Source License
public static String getEasterEggCape() { DateTime now = DateTime.now(); if (halloween.getDayOfMonth() == now.getDayOfMonth() && halloween.getMonthOfYear() == now.getMonthOfYear()) { return "http://cdn.getspout.org/img/cape/halloween1.png"; }/*from ww w .j ava 2 s . co m*/ return null; }
From source file:org.gravidence.gravifon.util.DateTimeUtils.java
License:Open Source License
/** * Converts datetime object to array of UTC datetime fields.<p> * Given datetime object is casted to UTC.<p> * Resulting array content is as follows: <code>[yyyy,MM,dd,HH,mm,ss,SSS]</code>. * //w w w. j a v a2 s . c o m * @param value datetime object * @return array of UTC datetime fields */ public static int[] dateTimeToArray(DateTime value) { int[] result; if (value == null) { result = null; } else { result = new int[7]; DateTime valueUTC = value.toDateTime(DateTimeZone.UTC); result[0] = valueUTC.getYear(); result[1] = valueUTC.getMonthOfYear(); result[2] = valueUTC.getDayOfMonth(); result[3] = valueUTC.getHourOfDay(); result[4] = valueUTC.getMinuteOfHour(); result[5] = valueUTC.getSecondOfMinute(); result[6] = valueUTC.getMillisOfSecond(); } return result; }
From source file:org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.java
License:Open Source License
private static Map<String, Object> ingestTimeFields(DateTime ingestTime) { return ImmutableMap.<String, Object>builder().put("ingest_time", ingestTime.toString()) .put("ingest_time_epoch", ingestTime.getMillis()) .put("ingest_time_second", ingestTime.getSecondOfMinute()) .put("ingest_time_minute", ingestTime.getMinuteOfHour()) .put("ingest_time_hour", ingestTime.getHourOfDay()) .put("ingest_time_day", ingestTime.getDayOfMonth()) .put("ingest_time_month", ingestTime.getMonthOfYear()).put("ingest_time_year", ingestTime.getYear()) .build();//from ww w . j ava 2s . c om }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*from w w w . jav a 2s .c om*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.datetime.DateTimeService.java
License:Apache License
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/* ww w . j a v a2s . c om*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }