use of org.joda.time.DateTimeZone in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method testWithMultipleEntitlementsImpl.
private void testWithMultipleEntitlementsImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
clock.setDay(new LocalDate(2013, 1, 1));
final DateTimeZone accountTimeZone = DateTimeZone.UTC;
final UUID accountId = UUID.randomUUID();
final String externalKey = "foo";
final UUID entitlementId1 = UUID.fromString("cf5a597a-cf15-45d3-8f02-95371be7f927");
final UUID entitlementId2 = UUID.fromString("e37cc97a-7b98-4ab6-a29a-7259e45c3366");
final List<SubscriptionBaseTransition> allTransitions1 = new ArrayList<SubscriptionBaseTransition>();
final List<SubscriptionBaseTransition> allTransitions2 = new ArrayList<SubscriptionBaseTransition>();
final List<BlockingState> blockingStatesEnt1 = new ArrayList<BlockingState>();
final List<BlockingState> blockingStatesEnt2 = new ArrayList<BlockingState>();
DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
final SubscriptionBaseTransition ent1Tr1 = createTransition(entitlementId1, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial1");
allTransitions1.add(ent1Tr1);
if (!regressionFlagForOlderVersionThan_0_17_X) {
final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStatesEnt1.add(bsCreate);
}
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final SubscriptionBaseTransition ent2Tr1 = createTransition(entitlementId2, EventType.API_USER, ApiEventType.TRANSFER, effectiveDate, clock.getUTCNow(), null, "phase2");
allTransitions2.add(ent2Tr1);
if (!regressionFlagForOlderVersionThan_0_17_X) {
final BlockingState bsCreate2 = new DefaultBlockingState(UUID.randomUUID(), entitlementId2, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStatesEnt2.add(bsCreate2);
}
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final SubscriptionBaseTransition ent1Tr2 = createTransition(entitlementId1, EventType.PHASE, null, effectiveDate, clock.getUTCNow(), "trial1", "phase1");
allTransitions1.add(ent1Tr2);
effectiveDate = effectiveDate.plusDays(5);
clock.addDays(5);
final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStatesEnt1.add(bs1);
blockingStatesEnt2.add(bs1);
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final SubscriptionBaseTransition ent1Tr3 = createTransition(entitlementId1, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "phase1", null);
allTransitions1.add(ent1Tr3);
final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), entitlementId1, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
blockingStatesEnt1.add(bs2);
final List<Entitlement> entitlements = new ArrayList<Entitlement>();
final Entitlement entitlement1 = createEntitlement(entitlementId1, allTransitions1, blockingStatesEnt1);
entitlements.add(entitlement1);
final Entitlement entitlement2 = createEntitlement(entitlementId2, allTransitions2, blockingStatesEnt2);
entitlements.add(entitlement2);
final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
assertEquals(events.size(), 9);
assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(ent1Tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(ent1Tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(ent2Tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(ent2Tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(ent1Tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(7).getEffectiveDate().compareTo(new LocalDate(ent1Tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.PHASE);
assertEquals(events.get(5).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
assertEquals(events.get(6).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
assertEquals(events.get(7).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
assertEquals(events.get(8).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
assertEquals(events.get(0).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(2).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(3).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(4).getServiceName(), EntitlementOrderingBase.ENT_BILLING_SERVICE_NAME);
assertEquals(events.get(5).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(6).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(7).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(8).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertNull(events.get(0).getPrevPhase());
assertEquals(events.get(0).getNextPhase().getName(), "trial1");
assertNull(events.get(1).getPrevPhase());
assertEquals(events.get(1).getNextPhase().getName(), "trial1");
assertNull(events.get(2).getPrevPhase());
assertEquals(events.get(2).getNextPhase().getName(), "phase2");
assertNull(events.get(3).getPrevPhase());
assertEquals(events.get(3).getNextPhase().getName(), "phase2");
assertEquals(events.get(4).getPrevPhase().getName(), "trial1");
assertEquals(events.get(4).getNextPhase().getName(), "phase1");
assertEquals(events.get(5).getPrevPhase().getName(), "phase1");
assertEquals(events.get(5).getNextPhase().getName(), "phase1");
assertEquals(events.get(6).getPrevPhase().getName(), "phase2");
assertEquals(events.get(6).getNextPhase().getName(), "phase2");
assertEquals(events.get(7).getPrevPhase().getName(), "phase1");
assertNull(events.get(7).getNextPhase());
assertEquals(events.get(8).getPrevPhase().getName(), "phase1");
assertNull(events.get(8).getNextPhase());
}
use of org.joda.time.DateTimeZone in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method testCancelBundleBeforeSubscriptionImpl.
private void testCancelBundleBeforeSubscriptionImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
clock.setDay(new LocalDate(2013, 1, 1));
final DateTimeZone accountTimeZone = DateTimeZone.UTC;
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final String externalKey = "foo";
final UUID entitlementId = UUID.randomUUID();
final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
allTransitions.add(tr1);
if (!regressionFlagForOlderVersionThan_0_17_X) {
final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bsCreate);
}
// Block the bundle before the subscription
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CANCELLED, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bs1);
effectiveDate = effectiveDate.plusDays(15);
clock.addDays(15);
final SubscriptionBaseTransition tr2 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CANCEL, effectiveDate, clock.getUTCNow(), "trial", null);
allTransitions.add(tr2);
final List<Entitlement> entitlements = new ArrayList<Entitlement>();
final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
entitlements.add(entitlement);
final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
assertEquals(timeline.getAccountId(), accountId);
assertEquals(timeline.getBundleId(), bundleId);
assertEquals(timeline.getExternalKey(), externalKey);
final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
assertEquals(events.size(), 4);
assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.STOP_ENTITLEMENT);
assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.STOP_BILLING);
assertEquals(events.get(0).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(2).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(3).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertNull(events.get(0).getPrevPhase());
assertNull(events.get(1).getPrevPhase());
assertEquals(events.get(1).getNextPhase().getName(), "trial");
assertEquals(events.get(3).getPrevPhase().getName(), "trial");
assertNull(events.get(3).getNextPhase());
}
use of org.joda.time.DateTimeZone in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method testVariousBlockingStatesAtTheSameEffectiveDateImpl.
private void testVariousBlockingStatesAtTheSameEffectiveDateImpl(final boolean regressionFlagForOlderVersionThan_0_17_X) throws CatalogApiException {
clock.setDay(new LocalDate(2013, 1, 1));
final DateTimeZone accountTimeZone = DateTimeZone.UTC;
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final String externalKey = "foo";
final UUID entitlementId = UUID.randomUUID();
final List<SubscriptionBaseTransition> allTransitions = new ArrayList<SubscriptionBaseTransition>();
final List<BlockingState> blockingStates = new ArrayList<BlockingState>();
DateTime effectiveDate = new DateTime(2013, 1, 1, 15, 43, 25, 0, DateTimeZone.UTC);
final SubscriptionBaseTransition tr1 = createTransition(entitlementId, EventType.API_USER, ApiEventType.CREATE, effectiveDate, clock.getUTCNow(), null, "trial");
allTransitions.add(tr1);
if (!regressionFlagForOlderVersionThan_0_17_X) {
final BlockingState bsCreate = new DefaultBlockingState(UUID.randomUUID(), entitlementId, BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bsCreate);
}
// 2013-02-10
effectiveDate = effectiveDate.plusDays(40);
clock.addDays(40);
final BlockingState bs1 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, true, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 0L);
blockingStates.add(bs1);
// Same timestamp on purpose
final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CLEAR, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 1L);
blockingStates.add(bs2);
// 2013-02-20
effectiveDate = effectiveDate.plusDays(10);
clock.addDays(10);
final BlockingState bs3 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_BLOCKED, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, true, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 2L);
blockingStates.add(bs3);
// 2013-03-02
effectiveDate = effectiveDate.plusDays(10);
clock.addDays(10);
final BlockingState bs4 = new DefaultBlockingState(UUID.randomUUID(), bundleId, BlockingStateType.SUBSCRIPTION_BUNDLE, DefaultEntitlementApi.ENT_STATE_CLEAR, DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 3L);
blockingStates.add(bs4);
final String overdueService = "overdue-service";
// 2013-03-04
effectiveDate = effectiveDate.plusDays(2);
clock.addDays(2);
final BlockingState bs5 = new DefaultBlockingState(UUID.randomUUID(), accountId, BlockingStateType.ACCOUNT, "OD1", overdueService, false, false, false, effectiveDate, clock.getUTCNow(), clock.getUTCNow(), 4L);
blockingStates.add(bs5);
final List<Entitlement> entitlements = new ArrayList<Entitlement>();
final Entitlement entitlement = createEntitlement(entitlementId, allTransitions, blockingStates);
entitlements.add(entitlement);
final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, entitlements, internalCallContext);
final List<SubscriptionEvent> events = timeline.getSubscriptionEvents();
assertEquals(events.size(), 11);
assertEquals(events.get(0).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(7).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(9).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(10).getEffectiveDate().compareTo(new LocalDate(bs5.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(0).getSubscriptionEventType(), SubscriptionEventType.START_ENTITLEMENT);
assertEquals(events.get(1).getSubscriptionEventType(), SubscriptionEventType.START_BILLING);
assertEquals(events.get(2).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
assertEquals(events.get(3).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING);
assertEquals(events.get(4).getSubscriptionEventType(), SubscriptionEventType.RESUME_ENTITLEMENT);
assertEquals(events.get(5).getSubscriptionEventType(), SubscriptionEventType.RESUME_BILLING);
assertEquals(events.get(6).getSubscriptionEventType(), SubscriptionEventType.PAUSE_ENTITLEMENT);
assertEquals(events.get(7).getSubscriptionEventType(), SubscriptionEventType.PAUSE_BILLING);
assertEquals(events.get(8).getSubscriptionEventType(), SubscriptionEventType.RESUME_ENTITLEMENT);
assertEquals(events.get(9).getSubscriptionEventType(), SubscriptionEventType.RESUME_BILLING);
assertEquals(events.get(10).getSubscriptionEventType(), SubscriptionEventType.SERVICE_STATE_CHANGE);
assertEquals(events.get(0).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(1).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(2).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(3).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(4).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(5).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(6).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(7).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(8).getServiceName(), DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME);
assertEquals(events.get(9).getServiceName(), EntitlementOrderingBase.BILLING_SERVICE_NAME);
assertEquals(events.get(10).getServiceName(), overdueService);
assertNull(events.get(0).getPrevPhase());
assertNull(events.get(1).getPrevPhase());
assertEquals(events.get(1).getNextPhase().getName(), "trial");
assertEquals(events.get(2).getPrevPhase().getName(), "trial");
assertEquals(events.get(2).getNextPhase().getName(), "trial");
assertEquals(events.get(3).getPrevPhase().getName(), "trial");
assertEquals(events.get(3).getNextPhase().getName(), "trial");
assertEquals(events.get(4).getPrevPhase().getName(), "trial");
assertEquals(events.get(4).getNextPhase().getName(), "trial");
assertEquals(events.get(5).getPrevPhase().getName(), "trial");
assertEquals(events.get(5).getNextPhase().getName(), "trial");
assertEquals(events.get(6).getPrevPhase().getName(), "trial");
assertEquals(events.get(6).getNextPhase().getName(), "trial");
assertEquals(events.get(7).getPrevPhase().getName(), "trial");
assertEquals(events.get(7).getNextPhase().getName(), "trial");
assertEquals(events.get(8).getPrevPhase().getName(), "trial");
assertEquals(events.get(8).getNextPhase().getName(), "trial");
assertEquals(events.get(9).getPrevPhase().getName(), "trial");
assertEquals(events.get(9).getNextPhase().getName(), "trial");
assertEquals(events.get(10).getPrevPhase().getName(), "trial");
assertEquals(events.get(10).getNextPhase().getName(), "trial");
}
use of org.joda.time.DateTimeZone in project Xponents by OpenSextant.
the class DateNormalization method normalize_date.
/*
*
* #DEFINE MON_ABBREV JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEPT?|OCT|NOV|DEC
#DEFINE MON_NAME [A-Z]{3}\w{0,8}
#DEFINE YEAR [12]\d{3}
#DEFINE YY \d\d
#DEFINE YEARYY \d{2,4}
#DEFINE MM [01]\d
#DEFINE DD [0-3]\d
#DEFINE SHORT_TZ [A-Z]
#DEFINE hh [0-2]\d
#DEFINE mm [0-5]\d
#DEFINE DOM [0-3]?\d
#DEFINE MONTH [01]?\d
#DEFINE LONG_TZ [A-Z]{3,5}
*/
/**
* For now this reports only DATE and standard TIME fields. Timezone is
* still TODO.
*
* TODO: throw NormalizationException
*
* @param elements pattern fields
* @param dt found date
* @throws ParseException the parse exception
*/
public static void normalize_date(java.util.Map<String, String> elements, DateMatch dt) throws ParseException {
// Parse years.
int year = normalize_year(elements);
if (year == INVALID_DATE) {
return;
}
if (year > MAXIMUM_YEAR) {
// HHMM can look like a year, e.g., 2100h or 2300 PM
return;
}
dt.resolution = DateMatch.TimeResolution.YEAR;
int month = normalize_month(elements);
if (month == INVALID_DATE) {
month = normalize_month_name(elements);
}
if (month == INVALID_DATE) {
return;
}
DateTime _cal = new DateTime(year, month, 1, 0, 0, DateTimeZone.UTC);
dt.resolution = DateMatch.TimeResolution.MONTH;
int dom = normalize_day(elements);
// If you got this far, then assume Day of Month is 1 (first of the month)
if (dom == INVALID_DATE) {
// No date found, resolution is month
dom = 1;
} else if (dom == 0) {
return;
} else {
dt.resolution = DateMatch.TimeResolution.DAY;
}
// Normalize Time fields found, H, M, s.SSS, etc.
//
_cal = _cal.withDayOfMonth(dom);
// For normal M/D/Y patterns, set the default time to noon, UTC
// Overall, we want to ensure that the general yyyy-mm-dd form is not impacted
// by time zone and default hour of 00:00; -- this generally would yield a date format a day early for ALL US timezones.
//
// Time res: the presence of a field, hh, mm, or ss means the pattern has that level of resolution.
// So even if time is 00:00:00Z -- all zeroes -- the resolution is still SECONDS.
//
int hour = normalize_time(elements, "hh");
if (hour >= 0) {
// Only if HH:MM... is present do we try to detect TZ.
//
DateTimeZone tz = normalize_tz(elements);
if (tz != null) {
_cal = _cal.withZone(tz);
}
// NON-zero hour.
dt.resolution = DateMatch.TimeResolution.HOUR;
int min = normalize_time(elements, "mm");
if (min >= 0) {
dt.resolution = DateMatch.TimeResolution.MINUTE;
// NON-zero minutes
_cal = _cal.withHourOfDay(hour);
_cal = _cal.withMinuteOfHour(min);
} else {
// No minutes
_cal = _cal.withHourOfDay(hour);
}
} else {
// No hour; default is 12:00 UTC.
_cal = _cal.withHourOfDay(12);
}
dt.datenorm = new Date(_cal.getMillis());
}
use of org.joda.time.DateTimeZone in project joda-time by JodaOrg.
the class TestCopticChronology method testDurationFields.
//-----------------------------------------------------------------------
public void testDurationFields() {
final CopticChronology coptic = CopticChronology.getInstance();
assertEquals("eras", coptic.eras().getName());
assertEquals("centuries", coptic.centuries().getName());
assertEquals("years", coptic.years().getName());
assertEquals("weekyears", coptic.weekyears().getName());
assertEquals("months", coptic.months().getName());
assertEquals("weeks", coptic.weeks().getName());
assertEquals("days", coptic.days().getName());
assertEquals("halfdays", coptic.halfdays().getName());
assertEquals("hours", coptic.hours().getName());
assertEquals("minutes", coptic.minutes().getName());
assertEquals("seconds", coptic.seconds().getName());
assertEquals("millis", coptic.millis().getName());
assertEquals(false, coptic.eras().isSupported());
assertEquals(true, coptic.centuries().isSupported());
assertEquals(true, coptic.years().isSupported());
assertEquals(true, coptic.weekyears().isSupported());
assertEquals(true, coptic.months().isSupported());
assertEquals(true, coptic.weeks().isSupported());
assertEquals(true, coptic.days().isSupported());
assertEquals(true, coptic.halfdays().isSupported());
assertEquals(true, coptic.hours().isSupported());
assertEquals(true, coptic.minutes().isSupported());
assertEquals(true, coptic.seconds().isSupported());
assertEquals(true, coptic.millis().isSupported());
assertEquals(false, coptic.centuries().isPrecise());
assertEquals(false, coptic.years().isPrecise());
assertEquals(false, coptic.weekyears().isPrecise());
assertEquals(false, coptic.months().isPrecise());
assertEquals(false, coptic.weeks().isPrecise());
assertEquals(false, coptic.days().isPrecise());
assertEquals(false, coptic.halfdays().isPrecise());
assertEquals(true, coptic.hours().isPrecise());
assertEquals(true, coptic.minutes().isPrecise());
assertEquals(true, coptic.seconds().isPrecise());
assertEquals(true, coptic.millis().isPrecise());
final CopticChronology copticUTC = CopticChronology.getInstanceUTC();
assertEquals(false, copticUTC.centuries().isPrecise());
assertEquals(false, copticUTC.years().isPrecise());
assertEquals(false, copticUTC.weekyears().isPrecise());
assertEquals(false, copticUTC.months().isPrecise());
assertEquals(true, copticUTC.weeks().isPrecise());
assertEquals(true, copticUTC.days().isPrecise());
assertEquals(true, copticUTC.halfdays().isPrecise());
assertEquals(true, copticUTC.hours().isPrecise());
assertEquals(true, copticUTC.minutes().isPrecise());
assertEquals(true, copticUTC.seconds().isPrecise());
assertEquals(true, copticUTC.millis().isPrecise());
final DateTimeZone gmt = DateTimeZone.forID("Etc/GMT");
final CopticChronology copticGMT = CopticChronology.getInstance(gmt);
assertEquals(false, copticGMT.centuries().isPrecise());
assertEquals(false, copticGMT.years().isPrecise());
assertEquals(false, copticGMT.weekyears().isPrecise());
assertEquals(false, copticGMT.months().isPrecise());
assertEquals(true, copticGMT.weeks().isPrecise());
assertEquals(true, copticGMT.days().isPrecise());
assertEquals(true, copticGMT.halfdays().isPrecise());
assertEquals(true, copticGMT.hours().isPrecise());
assertEquals(true, copticGMT.minutes().isPrecise());
assertEquals(true, copticGMT.seconds().isPrecise());
assertEquals(true, copticGMT.millis().isPrecise());
}
Aggregations