public void testToString() { DateTimeZone paris = DateTimeZone.forID("Europe/Paris"); ISOChronology isoParis = ISOChronology.getInstance(paris); assertEquals("ISOChronology[Europe/Paris]", isoParis.toString()); assertEquals("GJChronology[Europe/Paris]", GJChronology.getInstance(paris).toString()); assertEquals("GregorianChronology[Europe/Paris]", GregorianChronology.getInstance(paris).toString()); assertEquals("JulianChronology[Europe/Paris]", JulianChronology.getInstance(paris).toString()); assertEquals("BuddhistChronology[Europe/Paris]", BuddhistChronology.getInstance(paris).toString()); assertEquals("CopticChronology[Europe/Paris]", CopticChronology.getInstance(paris).toString()); assertEquals("EthiopicChronology[Europe/Paris]", EthiopicChronology.getInstance(paris).toString()); assertEquals("IslamicChronology[Europe/Paris]", IslamicChronology.getInstance(paris).toString()); assertEquals("LenientChronology[ISOChronology[Europe/Paris]]", LenientChronology.getInstance(isoParis).toString()); assertEquals("StrictChronology[ISOChronology[Europe/Paris]]", StrictChronology.getInstance(isoParis).toString()); assertEquals("LimitChronology[ISOChronology[Europe/Paris], NoLimit, NoLimit]", LimitChronology.getInstance(isoParis, null, null).toString()); assertEquals("ZonedChronology[ISOChronology[UTC], Europe/Paris]", ZonedChronology.getInstance(isoParis, paris).toString()); }
public String getAsString(FacesContext context, UIComponent component, Object value) { if (value == null || !(value instanceof Date)) return null; DateFormat formatter = new SimpleDateFormat(dateFormat); String formattedDate = new String(); if(siteProperties.getEthiopianCalendar()){ // Create Ethiopian Chronology Chronology chron_eth = EthiopicChronology.getInstance(DateTimeZone.getDefault()); DateTime dt_greg = new DateTime((Date)value).withChronology(GregorianChronology.getInstance(DateTimeZone.forID("Africa/Addis_Ababa"))); DateTime dt_eth = dt_greg.withChronology(chron_eth); formattedDate = DateTimeFormat.forPattern("dd/MM/yyyy").print(dt_eth); } else{ Date calendar = (Date) value; formattedDate = formatter.format(calendar); } return formattedDate; }
public String formatDate(Calendar calendar) { String formattedDate; if(siteProperties.getEthiopianCalendar()){ Chronology chron_eth = EthiopicChronology.getInstance(DateTimeZone.getDefault()); DateTime dt_greg = new DateTime(calendar).withChronology(GregorianChronology.getInstance(DateTimeZone.forID("Africa/Addis_Ababa"))); DateTime dt_eth = dt_greg.withChronology(chron_eth); formattedDate = DateTimeFormat.forPattern(siteProperties.getDateFormat()).print(dt_eth); } else{ SimpleDateFormat format = new SimpleDateFormat(siteProperties.getDateFormat()); formattedDate = format.format(calendar.getTime()); } return formattedDate; }
@Test public void testConversion() throws Exception { final DateTimeZone currentZone = DateTimeZone.forOffsetHours(2); final DateTime now = DateTime.now(); Long jodaTimestamp = jodaTimePropertyConverter.convertToDatabaseValue(now .withZone(DateTimeZone.forOffsetHours(-23)) .withChronology(EthiopicChronology.getInstance())); DateTime dateTime = jodaTimePropertyConverter.convertToEntityProperty(jodaTimestamp); Assert.assertNotNull(dateTime); Long jodaTimestamp2 = jodaTimePropertyConverter.convertToDatabaseValue(dateTime); assertThat(now.withZone(currentZone), equalTo(dateTime.withZone(currentZone))); assertThat(jodaTimestamp, equalTo(jodaTimestamp2)); }
private static String ConvertToEthiopian(int gregorianYear, int gregorianMonth, int gregorianDay, String format) { Chronology chron_eth = EthiopicChronology.getInstance(); Chronology chron_greg = GregorianChronology.getInstance(); DateTime jodaDateTime = new DateTime(gregorianYear, gregorianMonth, gregorianDay, 0, 0, 0, chron_greg); DateTime dtEthiopic = jodaDateTime.withChronology(chron_eth); DateUtils.CalendarStrings strings = getStringsWithMonth(getMonthsArray("ethiopian_months")); DateUtils.DateFields df = DateUtils.getFieldsForNonGregorianCalendar(dtEthiopic.getYear(), dtEthiopic.getMonthOfYear(), dtEthiopic.getDayOfMonth()); return DateUtils.format(df, format, strings); }
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { Calendar earliestEnumerationDate = null; System.out.println("CheckMinimumEnumerationStartDateValidator: " + properties.getEthiopianCalendar() + " " + value.getClass()); try { earliestEnumerationDate = calendarUtil.parseDate(properties.getEarliestEnumerationDate()); } catch(Exception e) { } Calendar recordedDate = null; if(properties.getEthiopianCalendar()){ Chronology chron_eth = EthiopicChronology.getInstance(DateTimeZone.getDefault()); DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy").withChronology(chron_eth); DateTime dt_eth = new DateTime((Date)value).withChronology(chron_eth); // DateTime dt_greg = dt_eth.withChronology(GregorianChronology.getInstance(DateTimeZone.forID("Africa/Addis_Ababa"))); recordedDate = dt_eth.toGregorianCalendar(); System.out.println("recorded date back in gregorian: " + recordedDate.getTime()); } else{ Date date = (Date)value; recordedDate = Calendar.getInstance(); recordedDate.setTime(date); } if (recordedDate.before(earliestEnumerationDate)) { FacesMessage message = new FacesMessage("The specified date is before the minimum date of enumeration : " + properties.getEarliestEnumerationDate()); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } }
protected EthiopianCalendar() { super( EthiopicChronology.getInstance( DateTimeZone.getDefault() ) ); }
public String getAsString(FacesContext context, UIComponent component, Object value) { DateFormat formatter = new SimpleDateFormat(dateFormat); String formattedDate = new String(); if(siteProperties.getEthiopianCalendar()){ // Create Ethiopian Chronology Chronology chron_eth = EthiopicChronology.getInstance(DateTimeZone.getDefault()); DateTime dt_greg = new DateTime((Calendar)value).withChronology(GregorianChronology.getInstance(DateTimeZone.forID("Africa/Addis_Ababa"))); DateTime dt_eth = dt_greg.withChronology(chron_eth); formattedDate = DateTimeFormat.forPattern("dd/MM/yyyy").print(dt_eth); } else{ Calendar calendar = (Calendar) value; formattedDate = formatter.format(calendar.getTime()); } return formattedDate; }