List of usage examples for org.joda.time LocalDate now
public static LocalDate now()
ISOChronology
in the default time zone. From source file:act.apidoc.Endpoint.java
License:Apache License
private Object generateSampleData(BeanSpec spec, Set<Type> typeChain, List<String> nameChain) { Type type = spec.type();/*from w ww .j a va2s. c o m*/ if (typeChain.contains(type) && !isCollection(type)) { return S.concat(spec.name(), ":", type); // circular reference detected } typeChain.add(type); String name = spec.name(); if (S.notBlank(name)) { nameChain.add(name); } if (null != fastJsonPropertyPreFilter) { String path = S.join(nameChain).by(".").get(); if (!fastJsonPropertyPreFilter.matches(path)) { return null; } } Class<?> classType = spec.rawType(); try { if (void.class == classType || Void.class == classType || Result.class.isAssignableFrom(classType)) { return null; } if (Object.class == classType) { return "<Any>"; } try { if (classType.isEnum()) { Object[] ea = classType.getEnumConstants(); int len = ea.length; return 0 < len ? ea[N.randInt(len)] : null; } else if (Locale.class == classType) { return (defLocale); } else if (String.class == classType) { String mockValue = S.random(5); if (spec.hasAnnotation(Sensitive.class)) { return Act.crypto().encrypt(mockValue); } return S.random(5); } else if (classType.isArray()) { Object sample = Array.newInstance(classType.getComponentType(), 2); Array.set(sample, 0, generateSampleData(BeanSpec.of(classType.getComponentType(), Act.injector()), C.newSet(typeChain), C.newList(nameChain))); Array.set(sample, 1, generateSampleData(BeanSpec.of(classType.getComponentType(), Act.injector()), C.newSet(typeChain), C.newList(nameChain))); return sample; } else if ($.isSimpleType(classType)) { if (Enum.class == classType) { return "<Any Enum>"; } if (!classType.isPrimitive()) { classType = $.primitiveTypeOf(classType); } return StringValueResolver.predefined().get(classType).resolve(null); } else if (LocalDateTime.class.isAssignableFrom(classType)) { return LocalDateTime.now(); } else if (DateTime.class.isAssignableFrom(classType)) { return DateTime.now(); } else if (LocalDate.class.isAssignableFrom(classType)) { return LocalDate.now(); } else if (LocalTime.class.isAssignableFrom(classType)) { return LocalTime.now(); } else if (Date.class.isAssignableFrom(classType)) { return new Date(); } else if (classType.getName().contains(".ObjectId")) { return "<id>"; } else if (BigDecimal.class == classType) { return BigDecimal.valueOf(1.1); } else if (BigInteger.class == classType) { return BigInteger.valueOf(1); } else if (ISObject.class.isAssignableFrom(classType)) { return null; } else if (Map.class.isAssignableFrom(classType)) { Map map = $.cast(Act.getInstance(classType)); List<Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { typeParams = Generics.typeParamImplementations(classType, Map.class); } if (typeParams.size() < 2) { map.put(S.random(), S.random()); map.put(S.random(), S.random()); } else { Type keyType = typeParams.get(0); Type valType = typeParams.get(1); map.put(generateSampleData(BeanSpec.of(keyType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain)), generateSampleData(BeanSpec.of(valType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); map.put(generateSampleData(BeanSpec.of(keyType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain)), generateSampleData(BeanSpec.of(valType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); } } else if (Iterable.class.isAssignableFrom(classType)) { Collection col = $.cast(Act.getInstance(classType)); List<Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { typeParams = Generics.typeParamImplementations(classType, Map.class); } if (typeParams.isEmpty()) { col.add(S.random()); } else { Type componentType = typeParams.get(0); col.add(generateSampleData(BeanSpec.of(componentType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); col.add(generateSampleData(BeanSpec.of(componentType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); } return col; } if (null != stringValueResolver(classType)) { return S.random(5); } Object obj = Act.getInstance(classType); List<Field> fields = $.fieldsOf(classType); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers())) { continue; } if (ParamValueLoaderService.shouldWaive(field)) { continue; } Class<?> fieldType = field.getType(); Object val = null; try { field.setAccessible(true); val = generateSampleData(BeanSpec.of(field, Act.injector()), C.newSet(typeChain), C.newList(nameChain)); Class<?> valType = null == val ? null : val.getClass(); if (null != valType && fieldType.isAssignableFrom(valType)) { field.set(obj, val); } } catch (Exception e) { LOGGER.warn("Error setting value[%s] to field[%s.%s]", val, classType.getSimpleName(), field.getName()); } } return obj; } catch (Exception e) { LOGGER.warn("error generating sample data for type: %s", classType); return null; } } finally { //typeChain.remove(classType); } }
From source file:at.jclehner.rxdroid.DrugEditFragment.java
License:Open Source License
private boolean fixInvalidRepeatOrigin(final Drug drug) { final LocalDate dateOnly = LocalDate.fromDateFields(drug.getRepeatOrigin()); if (fixInvalidRepeatOrigin(drug, dateOnly)) return true; else if (fixInvalidRepeatOrigin(drug, drug.getNextScheduledDate(LocalDate.now()))) return true; else {//from www.j a va 2 s . co m final DatePickerDialog dialog = new DatePickerDialog(getActivity(), dateOnly, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePickerDialog dialog, LocalDate date) { updateRepeatOrigin(drug, date); updatePreferenceHierarchy(); } }); dialog.setTitle(R.string._title_repetition_origin); dialog.setCancelable(false); dialog.show(); return false; } }
From source file:au.com.scds.chats.dom.general.Person.java
License:Apache License
@Programmatic() public Integer getDaysUntilBirthday(LocalDate futureDate) { if (futureDate == null) futureDate = LocalDate.now(); Integer diff = getBirthdate().getDayOfYear() - futureDate.getDayOfYear(); if (diff < 0) { return 365 + diff; } else {// w w w .j a v a 2 s . c o m return diff; } }
From source file:au.com.scds.chats.dom.general.Person.java
License:Apache License
@Programmatic() public Integer getAge(LocalDate futureDate) { if (futureDate == null) futureDate = LocalDate.now(); Period p = new Period(getBirthdate(), futureDate); return p.getYears(); }
From source file:au.com.scds.chats.dom.participant.Participants.java
License:Apache License
@Action(semantics = SemanticsOf.SAFE) @ActionLayout(bookmarking = BookmarkPolicy.NEVER) //@MemberOrder(sequence = "1") //@SuppressWarnings("all") public List<Participant> listActive(@Parameter(optionality = Optionality.MANDATORY) AgeGroup ageClass) { switch (ageClass) { case All:// w ww .j a v a2s . c om return container.allMatches( new QueryDefault<>(Participant.class, "listParticipantsByStatus", "status", Status.ACTIVE)); case Under_Sixty_Five: LocalDate lowerLimit = LocalDate.now().minusYears(65); return container .allMatches(new QueryDefault<>(Participant.class, "listParticipantsByStatusAndBirthdateAbove", "status", Status.ACTIVE, "lowerLimit", lowerLimit)); case Sixty_Five_and_Over: LocalDate upperLimit = LocalDate.now().minusYears(65).plusDays(1); return container .allMatches(new QueryDefault<>(Participant.class, "listParticipantsByStatusAndBirthdateBelow", "status", Status.ACTIVE, "upperLimit", upperLimit)); default: return null; } /* * TODO replace all queries with typesafe final QParticipant p = * QParticipant.candidate(); return * isisJdoSupport.executeQuery(Participant.class, * p.status.eq(Status.ACTIVE)); */ }
From source file:beans.Compensation.java
public Compensation() { isActive = false; beginDate = LocalDate.now(); endDate = LocalDate.now(); }
From source file:br.edu.unirio.pm.dao.VendasDAO.java
public LocalDate obterDataDaVendaMaisAtual() throws SQLException { try {// w w w . j av a2s .c om consulta = SELECT_MAX_DATA; LocalDate dataVendaMaisAtual = LocalDate.now(); FabricaConexao.iniciarConexao(); comando = FabricaConexao.criarComando(consulta); resultado = comando.executeQuery(); while (resultado.next()) dataVendaMaisAtual = new LocalDate(resultado.getDate(1)); return dataVendaMaisAtual; } finally { FabricaConexao.fecharComando(comando); FabricaConexao.fecharConexao(); } }
From source file:br.edu.unirio.pm.dao.VendasDAO.java
public LocalDate obterDataDaVendaMaisAntiga() throws SQLException { try {//from w ww .j a va 2s .c o m consulta = SELECT_MIN_DATA; LocalDate dataVendaMaisAntiga = LocalDate.now(); FabricaConexao.iniciarConexao(); comando = FabricaConexao.criarComando(consulta); resultado = comando.executeQuery(); while (resultado.next()) dataVendaMaisAntiga = new LocalDate(resultado.getDate(1)); return dataVendaMaisAntiga; } finally { FabricaConexao.fecharComando(comando); FabricaConexao.fecharConexao(); } }
From source file:ch.eitchnet.android.mabea.MabeaParsing.java
License:Open Source License
public static LocalDateTime parseStateTime(String value) throws MabeaParsingException { try {// w w w .j av a2 s . c om int posOpenBracket = value.indexOf('('); int posCloseBracket = value.indexOf(')'); String time = value.substring(posOpenBracket + 1, posCloseBracket); LocalTime localTime = DateTimeFormat.forPattern("HH:mm").parseLocalTime(time); return LocalDate.now().toLocalDateTime(localTime); } catch (Exception e) { throw new MabeaParsingException("State time can not be parsed from value " + value, e); } }
From source file:ch.eitchnet.android.mabea.model.MabeaContext.java
License:Open Source License
public Today getToday() { if (this.today == null) { MabeaState state = getConnection().getMabeaState(); LocalDateTime midnight = LocalDate.now().toLocalDateTime(LocalTime.MIDNIGHT); Booking initialBooking = new Booking(State.LOGGED_OUT, midnight, state.getBalance()); this.today = new Today(this.setting.getRequiredWorkPerDay(), initialBooking); }//from w ww .j av a 2 s . co m return this.today; }