use of org.joda.time.DateTime in project killbill by killbill.
the class DefaultSubscriptionBaseApiService method validateEffectiveDate.
private void validateEffectiveDate(final SubscriptionBase subscription, final ReadableInstant effectiveDate) throws SubscriptionBaseApiException {
final SubscriptionBaseTransition previousTransition = subscription.getPreviousTransition();
// Our effectiveDate must be after or equal the last transition that already occured (START, PHASE1, PHASE2,...) or the startDate for future started subscription
final DateTime earliestValidDate = previousTransition != null ? previousTransition.getEffectiveTransitionTime() : subscription.getStartDate();
if (effectiveDate.isBefore(earliestValidDate)) {
throw new SubscriptionBaseApiException(ErrorCode.SUB_INVALID_REQUESTED_DATE, effectiveDate.toString(), previousTransition != null ? previousTransition.getEffectiveTransitionTime() : "null");
}
}
use of org.joda.time.DateTime in project killbill by killbill.
the class InternalCallContextFactory method createInternalCallContext.
// Used when we need to re-hydrate the callcontext with the account_record_id (when creating the account)
public InternalCallContext createInternalCallContext(final Long accountRecordId, final InternalCallContext context) {
final DateTimeZone fixedOffsetTimeZone = getFixedOffsetTimeZone(accountRecordId, context.getTenantRecordId());
final DateTime referenceTime = getReferenceTime(accountRecordId, context.getTenantRecordId());
populateMDCContext(accountRecordId, context.getTenantRecordId());
return new InternalCallContext(context, accountRecordId, fixedOffsetTimeZone, referenceTime, clock.getUTCNow());
}
use of org.joda.time.DateTime in project killbill by killbill.
the class AuditLogModelDaoMapper method map.
@Override
public AuditLogModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
final UUID id = getUUID(r, "id");
final String tableName = r.getString("table_name");
final long targetRecordId = r.getLong("target_record_id");
final String changeType = r.getString("change_type");
final DateTime createdDate = getDateTime(r, "created_date");
final String createdBy = r.getString("created_by");
final String reasonCode = r.getString("reason_code");
final String comments = r.getString("comments");
final UUID userToken = getUUID(r, "user_token");
final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate);
// TODO - we have the tenant_record_id but not the tenant id here
final CallContext callContext = new DefaultCallContext(null, createdBy, createdDate, reasonCode, comments, userToken);
return new AuditLogModelDao(entityAudit, callContext);
}
use of org.joda.time.DateTime in project killbill by killbill.
the class AccountDateTimeUtils method getFixedOffsetTimeZone.
public static DateTimeZone getFixedOffsetTimeZone(final Account account) {
final DateTimeZone referenceDateTimeZone = account.getTimeZone();
final DateTime referenceDateTime = getReferenceDateTime(account);
// Check if DST was in effect at the reference date time
final boolean shouldUseDST = !referenceDateTimeZone.isStandardOffset(referenceDateTime.getMillis());
if (shouldUseDST) {
return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getOffset(referenceDateTime.getMillis()));
} else {
return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getStandardOffset(referenceDateTime.getMillis()));
}
}
use of org.joda.time.DateTime in project openhab1-addons by openhab.
the class SonosZonePlayer method setAlarm.
public boolean setAlarm(boolean alarmSwitch) {
List<SonosAlarm> sonosAlarms = getCurrentAlarmList();
if (isConfigured()) {
// find the nearest alarm - take the current time from the Sonos System, not the system where openhab is
// running
String currentLocalTime = getTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime currentDateTime = fmt.parseDateTime(currentLocalTime);
Duration shortestDuration = Period.days(10).toStandardDuration();
SonosAlarm firstAlarm = null;
for (SonosAlarm anAlarm : sonosAlarms) {
Duration duration = new Duration(currentDateTime, anAlarm.getStartTime());
if (anAlarm.getStartTime().isBefore(currentDateTime.plus(shortestDuration)) && anAlarm.getRoomUUID().equals(udn.getIdentifierString())) {
shortestDuration = duration;
firstAlarm = anAlarm;
}
}
// Set the Alarm
if (firstAlarm != null) {
if (alarmSwitch) {
firstAlarm.setEnabled(true);
} else {
firstAlarm.setEnabled(false);
}
return updateAlarm(firstAlarm);
} else {
return false;
}
} else {
return false;
}
}
Aggregations