List of usage examples for org.joda.time LocalDate now
public static LocalDate now()
ISOChronology
in the default time zone. From source file:dom.simple.Legajo.java
License:Open Source License
@Column(allowsNull = "true", name = "TARJETAS_ID") @MemberOrder(sequence = "1.1", name = "Nueva Tarjeta") @Named("Nueva Tarjeta") public Legajo create(final @Named("Titulo") String titulo, final @MaxLength(2048) @MultiLine @Named("Comentarios") String comentario, final @Named("Categoria de Tarjeta") ECategoria categoria) { final Tarjeta tarjeta = new Tarjeta(); LocalDate fecha = LocalDate.now(); tarjeta.setTitulo(titulo);/*from w w w. ja va2s.c o m*/ tarjeta.setComentarios(comentario); tarjeta.setFecha(fecha); tarjeta.setCategoria(categoria); addTarjeta(tarjeta); //container.persistIfNotAlready(tarjeta); addTarjeta(tarjeta); return this; }
From source file:domain.RaspberryPiGather.java
public WeatherReport gatherFrom() throws Exception { Client client = ClientBuilder.newClient(); WebTarget target = client.target(url).resolveTemplates(this.temperature); ObjectMapper objectMapper = new ObjectMapper(); String response = target.request(MediaType.APPLICATION_JSON).get(String.class); WeatherReport t = null;/*from w w w . j a v a 2s. com*/ try { JsonNode rootNode = objectMapper.readTree(response); JsonNode temp = rootNode.path("temp"); JsonNode humidity = rootNode.path("humidity"); LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); t = new WeatherReport(temp.doubleValue(), humidity.textValue(), date, time); } catch (Exception e) { } return t; }
From source file:domainapp.dom.reserva.Reservas.java
License:Apache License
@Programmatic public String validate1CrearReserva(final LocalDate fechaIn) { LocalDate hoyy = LocalDate.now(); if (fechaIn.isBefore(hoyy)) { return "Una Reserva no puede empezar en el pasado"; }//ww w. j a v a 2s .c om return null; }
From source file:edu.uic.apk.IDUbuilder1.java
License:Open Source License
public IDU generate_SynthNEP(HashMap<String, Object> generator_params) throws Exception { DrugUser modelDU = null;/*from ww w . j a v a 2 s. c o m*/ Integer max_trials = 50; if (generator_params.containsKey("max_trials")) { max_trials = (Integer) generator_params.get("max_trials"); } for (int trial = 0; trial < max_trials; trial++) { try { modelDU = pg.generate(generator_params); assert modelDU != null; break; } catch (Exception e) { System.out.println("x"); modelDU = null; } } if (modelDU == null) { throw new Exception("failed to generate"); } IDU idu = new IDU(); idu.setAgeStarted(modelDU.getAgeStarted()); LocalDate b_day = modelDU.getBirthDate(); LocalDate age_at_survey = modelDU.getSurveyDate(); LocalDate sim_date = APKBuilder.getSimulationDate(); b_day = b_day.plusYears(sim_date.getYear() - age_at_survey.getYear()); b_day = b_day.plusDays(sim_date.getDayOfYear() - age_at_survey.getDayOfYear()); b_day = b_day.plusDays((int) (0.05 * 365 * (RandomHelper.nextDouble() - 0.5))); //some slight jitter (0.05 of a year) idu.setBirthDate(b_day); //System.out.println("Age:" + idu.getAge() + "Model age:" + modelDU.getAge()); idu.setDatabaseLabel(modelDU.getDatabaseLabel()); idu.setEntryDate(LocalDate.now()); idu.setDrugGivingDegree(modelDU.getDrugGivingDegree()); idu.setDrugReceptDegree(modelDU.getDrugReceptDegree()); idu.setFractionReceptSharing(modelDU.getFractionReceptSharing()); idu.setGender(modelDU.getGender()); if (modelDU.getHcvState() == HCV_state.ABPOS) { double roll = RandomHelper.nextDouble() - ab_prob_chronic; if (roll < 0) { idu.setHcvInitialState(HCV_state.chronic); } else if (roll - ab_prob_acute < 0) { idu.setHcvInitialState(HCV_state.infectiousacute); } else { idu.setHcvInitialState(HCV_state.recovered); } } else { idu.setHcvInitialState(HCV_state.susceptible); } idu.setInjectionIntensity(modelDU.getInjectionIntensity()); if (idu.getName() == null) { if (idu.getGender() == Gender.Male) { idu.setName(IDU.male_names[RandomHelper.nextIntFromTo(0, IDU.male_names.length - 1)]); } else { idu.setName(IDU.female_names[RandomHelper.nextIntFromTo(0, IDU.female_names.length - 1)]); } } idu.setPreliminaryZip(modelDU.getPreliminaryZip()); idu.setRace(modelDU.getRace()); idu.setSyringe_source(modelDU.getSyringe_source()); return idu; }
From source file:edu.wisc.ssec.mcidasv.ui.JCalendarDateEditor.java
License:Open Source License
private Date attemptParsing(String text) { Date result = null;//from www . j a va 2 s . c o m try { if (dayOnly.matcher(text).matches()) { String full = LocalDate.now().getYear() + text; result = yearAndDay.parse(full); } else if (yearDay.matcher(text).matches()) { result = yearAndDay.parse(text); } else if (badYearDay.matcher(text).matches()) { result = badYearAndDay.parse(text); } else { result = dateFormatter.parse(text); } } catch (Exception e) { logger.trace("failed to parse '{}'", text); } return result; }
From source file:es.usc.citius.servando.calendula.activities.CaldroidSampleCustomAdapter.java
License:Open Source License
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View cellView = convertView;/*from www .j a v a 2s . c o m*/ // For reuse if (convertView == null) { cellView = inflater.inflate(R.layout.custom_calendar_cell, null); } int topPadding = cellView.getPaddingTop(); int leftPadding = cellView.getPaddingLeft(); int bottomPadding = cellView.getPaddingBottom(); int rightPadding = cellView.getPaddingRight(); TextView tv1 = (TextView) cellView.findViewById(R.id.tv1); TextView tv2 = (TextView) cellView.findViewById(R.id.tv2); tv1.setTextColor(Color.BLACK); // Get dateTime of this cell DateTime dateTime = this.datetimeList.get(position); Resources resources = context.getResources(); // Set color of the dates in previous / next month if (dateTime.getMonth() != month) { tv1.setTextColor(resources.getColor(com.caldroid.R.color.caldroid_darker_gray)); } boolean shouldResetDiabledView = false; boolean shouldResetSelectedView = false; // Customize for disabled dates and date outside min/max dates if ((minDateTime != null && dateTime.lt(minDateTime)) || (maxDateTime != null && dateTime.gt(maxDateTime)) || (disableDates != null && disableDates.indexOf(dateTime) != -1)) { tv1.setTextColor(CaldroidFragment.disabledTextColor); if (CaldroidFragment.disabledBackgroundDrawable == -1) { cellView.setBackgroundResource(com.caldroid.R.drawable.disable_cell); } else { cellView.setBackgroundResource(CaldroidFragment.disabledBackgroundDrawable); } if (dateTime.equals(getToday())) { cellView.setBackgroundResource(com.caldroid.R.drawable.red_border_gray_bg); } } else { shouldResetDiabledView = true; } // Customize for selected dates if (selectedDates != null && selectedDates.indexOf(dateTime) != -1) { cellView.setBackgroundColor(resources.getColor(com.caldroid.R.color.caldroid_sky_blue)); tv1.setTextColor(Color.BLACK); } else { shouldResetSelectedView = true; } if (shouldResetDiabledView && shouldResetSelectedView) { // Customize for today if (dateTime.equals(getToday())) { cellView.setBackgroundResource(com.caldroid.R.drawable.red_border); } else { cellView.setBackgroundResource(com.caldroid.R.drawable.cell_bg); } } tv1.setText("" + dateTime.getDay()); List<PickupInfo> pk = pkUtils.pickupsMap() .get(new LocalDate(dateTime.getMilliseconds(TimeZone.getDefault()))); if (pk != null && pk.size() > 0) { LocalDate today = LocalDate.now(); HashMap<Integer, String> colors = new HashMap<>(); for (int i = 0; i < pk.size(); i++) { PickupInfo pki = pk.get(i); Integer color = pkUtils.getPatient(pki).color(); if (!colors.containsKey(color)) { colors.put(color, pki.taken() ? takenSymbol : notTakenSymbol); } else if (!pki.taken()) { colors.put(color, pki.to().isAfter(today) ? notTakenSymbol : lostSymbol); } } String text = ""; for (Integer c : colors.keySet()) { text += colors.get(c); } Spannable span = new SpannableString(text); int i = 0; for (int color : colors.keySet()) { span.setSpan(new ForegroundColorSpan(color), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new RelativeSizeSpan(1.2f), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); i++; } tv2.setText(span); } else { tv2.setText(""); } // Somehow after setBackgroundResource, the padding collapse. // This is to recover the padding cellView.setPadding(leftPadding, topPadding, rightPadding, bottomPadding); // Set custom color if required setCustomResources(dateTime, cellView, tv1); return cellView; }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
License:Open Source License
public CharSequence getBestDayText() { final List<PickupInfo> urgent = pickupUtils.urgentMeds(); Pair<LocalDate, List<PickupInfo>> best = pickupUtils.getBestDay(); final List<PickupInfo> next = (best == null || best.first == null) ? new ArrayList<PickupInfo>() : best.second;/* w w w . ja va2 s. c o m*/ CharSequence msg = new SpannableString("No hai medicinas que recoger"); LocalDate today = LocalDate.now(); // there are not urgent meds, but there are others to pickup if (urgent.isEmpty() && best != null) { // Log.d("Calendar", "Urgent: " + urgent.size()); // Log.d("Calendar", "Next: " + next.size()); Log.d("Calendar", "there are not urgent meds, but there are others to pickup"); if (next.size() > 1) { msg = new SpannableString(getString(R.string.best_single_day_messge, best.first.toString(getString(R.string.best_date_format)), next.size()) + "\n\n"); } else { msg = new SpannableString(getString(R.string.best_single_day_messge_one_med, best.first.toString(getString(R.string.best_date_format))) + "\n\n"); } msg = addPickupList(msg, next); } // there are urgent meds Log.d("Calendar", "there are urgent meds"); if (!urgent.isEmpty()) { // and others Log.d("Calendar", "and others"); if (best != null) { String bestStr = best.equals(LocalDate.now().plusDays(1)) ? getString(R.string.calendar_date_tomorrow) : best.first.toString(getString(R.string.best_date_format)); // and the others date is near Log.d("Calendar", "and the others date is near"); if (today.plusDays(3).isAfter(best.first)) { List<PickupInfo> all = new ArrayList<>(); all.addAll(urgent); all.addAll(next); msg = new SpannableString( getString(R.string.best_single_day_messge, bestStr, all.size()) + "\n\n"); msg = addPickupList(msg, all); } // and the others date is not near else { Log.d("Calendar", "and the others date is not near"); msg = addPickupList(new SpannableString(getString(R.string.pending_meds_msg) + "\n\n"), urgent); msg = TextUtils.concat(msg, new SpannableString("\n")); if (next.size() > 1) { Log.d("Calendar", " size > 1"); msg = TextUtils.concat(msg, getString(R.string.best_single_day_messge_after_pending, bestStr, next.size()) + "\n\n"); } else { Log.d("Calendar", " size <= 1"); msg = TextUtils.concat(msg, getString(R.string.best_single_day_messge_after_pending_one_med, bestStr) + "\n\n"); } msg = addPickupList(msg, next); } } else { Log.d("Calendar", " there are only urgent meds"); // there are only urgent meds msg = addPickupList(getString(R.string.pending_meds_msg) + "\n\n", urgent); } } Log.d("BEST_DAY", msg.toString()); return msg; }
From source file:es.usc.citius.servando.calendula.activities.ConfirmActivity.java
License:Open Source License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); processIntent();//from w w w.java 2 s .c o m setContentView(R.layout.activity_confirm); isToday = LocalDate.now().equals(date); isInWindow = AlarmScheduler.isWithinDefaultMargins(date.toDateTime(time), this); DateTime dt = date.toDateTime(time); DateTime now = DateTime.now(); Pair<DateTime, DateTime> interval = getCheckMarginInterval(dt); isDistant = !new Interval(interval.first, interval.second).contains(now); color = AvatarMgr.colorsFor(getResources(), patient.avatar())[0]; color = Color.parseColor("#263238"); setupStatusBar(Color.TRANSPARENT); setupToolbar("", Color.TRANSPARENT, Color.WHITE); toolbar.setTitleTextColor(Color.WHITE); findViewById(R.id.imageView5).setBackgroundColor(patient.color()); fab = (FloatingActionButton) findViewById(R.id.myFAB); listView = (RecyclerView) findViewById(R.id.listView); avatar = (ImageView) findViewById(R.id.patient_avatar); title = (TextView) findViewById(R.id.routine_name); takeMadsMessage = (TextView) findViewById(R.id.textView3); chekAllOverlay = findViewById(R.id.check_overlay); checkAllImage = (ImageView) findViewById(R.id.check_all_image); avatarTitle = (ImageView) findViewById(R.id.patient_avatar_title); titleTitle = (TextView) findViewById(R.id.routine_name_title); friendlyTime = (TextView) findViewById(R.id.user_friendly_time); hour = (TextView) findViewById(R.id.routines_list_item_hour); minute = (TextView) findViewById(R.id.routines_list_item_minute); toolbarTitle = findViewById(R.id.toolbar_title); avatar.setImageResource(AvatarMgr.res(patient.avatar())); avatarTitle.setImageResource(AvatarMgr.res(patient.avatar())); titleTitle.setText(patient.name()); title.setText((isRoutine ? routine.name() : schedule.toReadableString(this))); takeMadsMessage.setText(isInWindow ? getString(R.string.agenda_zoom_meds_time) : getString(R.string.meds_from) + " " + date.toString("EEEE dd")); relativeTime = DateUtils.getRelativeTimeSpanString(dt.getMillis(), now.getMillis(), 5 * DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL).toString(); hour.setText(time.toString("kk:")); minute.setText(time.toString("mm")); friendlyTime.setText(relativeTime.substring(0, 1).toUpperCase() + relativeTime.substring(1)); if (isDistant) { fab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.android_orange_dark))); } fab.setImageDrawable(new IconicsDrawable(this).icon(CommunityMaterial.Icon.cmd_check_all).color(Color.WHITE) .sizeDp(24).paddingDp(0)); checkAllImage.setImageDrawable(new IconicsDrawable(this).icon(CommunityMaterial.Icon.cmd_check_all) .color(Color.WHITE).sizeDp(100).paddingDp(0)); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean somethingToCheck = false; for (DailyScheduleItem item : items) { if (!item.takenToday()) { somethingToCheck = true; break; } } if (somethingToCheck) { if (isDistant) { showEnsureConfirmDialog(new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { onClickFab(); } }, false); } else { onClickFab(); } } else { Snack.show(getResources().getString(R.string.all_meds_taken), ConfirmActivity.this); } } }); appBarLayout = (AppBarLayout) findViewById(R.id.appbar); toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); toolbarLayout.setContentScrimColor(patient.color()); setupListView(); if ("delay".equals(action)) { if (isRoutine && routine != null) { ReminderNotification.cancel(this, ReminderNotification.routineNotificationId(routine.getId().intValue())); } else if (schedule != null) { ReminderNotification.cancel(this, ReminderNotification.scheduleNotificationId(schedule.getId().intValue())); } showDelayDialog(); } }
From source file:es.usc.citius.servando.calendula.activities.SummaryCalendarActivity.java
License:Open Source License
private void setupCalendar() { calendar = (CalendarPickerView) findViewById(R.id.calendar_view); calendar.setVerticalScrollBarEnabled(false); RepetitionRule r;/*from w w w. j a va2 s.co m*/ String rule = getIntent().getStringExtra("rule"); String date = getIntent().getStringExtra("start"); int activeDays = getIntent().getIntExtra("active_days", -1); int restDays = getIntent().getIntExtra("rest_days", -1); LocalDate from = date != null ? LocalDate.parse(date, fmt) : LocalDate.now(); LocalDate to = from.plusMonths(6); if (rule != null) { r = new RepetitionRule(rule); List<DateTime> dates = r.occurrencesBetween(from.toDateTimeAtStartOfDay(), to.toDateTimeAtStartOfDay(), from.toDateTimeAtStartOfDay()); Set<Date> hdates = new HashSet<>(); for (DateTime d : dates) hdates.add(d.toDate()); List<CalendarCellDecorator> decorators = new ArrayList<>(); DateValue v = r.iCalRule().getUntil(); Date start = date != null ? from.toDate() : null; Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(new ArrayList<>(hdates), start, end, color)); calendar.setDecorators(decorators); } else if (activeDays > 0 && restDays > 0) { List<Date> hdates = new ArrayList<>(); LocalDate d = from.plusDays(0); // copy while (d.isBefore(to)) { if (ScheduleHelper.cycleEnabledForDate(d, from, activeDays, restDays)) { hdates.add(d.toDate()); } d = d.plusDays(1); } List<CalendarCellDecorator> decorators = new ArrayList<>(); //DateValue v = r.iCalRule().getUntil(); //Date start = date != null ? from.toDate() : null; //Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(hdates, from.toDate(), to.toDate(), color)); calendar.setDecorators(decorators); } calendar.init(from.toDate(), to.toDate()) .setShortWeekdays(getResources().getStringArray(R.array.calendar_weekday_names)); }
From source file:es.usc.citius.servando.calendula.DailyAgendaRecyclerAdapter.java
License:Open Source License
public void onBindViewSpacerItemViewHolder(SpacerItemViewHolder holder, DailyAgendaItemStub item, int position) { if (expanded) { int color = DB.patients().getActive(holder.itemView.getContext()).color(); // TODO: get from strings String title;/* www .j a v a 2 s . c om*/ if (item.date.equals(LocalDate.now())) { title = "Hoy"; } else if (item.date.equals(LocalDate.now().minusDays(1))) { title = "Ayer"; } else if (item.date.equals(LocalDate.now().plusDays(1))) { title = "Maana"; } else { title = item.date.toString("EEEE dd"); } holder.dayBg.setBackgroundColor(color); holder.day.setVisibility(View.VISIBLE); holder.day.setText(title); holder.parallax.updateParallax(); } holder.itemView.setVisibility(expanded ? View.VISIBLE : View.GONE); ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); int newHeight = expanded ? ScreenUtils.dpToPx(holder.itemView.getResources(), 80) : 0; if (params.height != newHeight) { params.height = newHeight; holder.itemView.setLayoutParams(params); } }