Java Code Examples for java.util.Date.before()

The following are Jave code examples for showing how to use before() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Guanajoven   File: EditTextValidations.java   View Source Code Vote up 6 votes
public static boolean compararFechaHora(EditText f1, EditText h1, String fec1, String fec2){
    Log.d("FECHAS", fec1 + "     " + fec2);
    Date d1 = DateUtilities.stringToDate(fec1);
    Date d2 = DateUtilities.stringToDate(fec2);

    if(d2.before(d1)){
        ((TextInputLayout)f1.getParent().getParent()).setErrorEnabled(true);
        ((TextInputLayout)f1.getParent().getParent()).setError("La fecha de fin no puede ser posterior a la de inicio.");
        ((TextInputLayout)h1.getParent().getParent()).setErrorEnabled(true);
        ((TextInputLayout)h1.getParent().getParent()).setError("");
        return false;
    }
    else{
        return true;
    }
}
 
Example 2
Project: dhus-core   File: ExecutorImpl.java   View Source Code Vote up 6 votes
/**
 * Returns a {@link List} of {@link Synchronizer} whose cron expression is
 * triggered between the given parameters.
 * @param start the /start/ Date (exclusive).
 * @param end   the /end/ Date (inclusive).
 * @return a {@link List} of {@link Synchronizer}.
 */
private List<StatSync> getToSync (Date start, Date end) throws InterruptedException
{
   List<StatSync> res = new LinkedList<> ();

   lockSyncMap.lockInterruptibly ();
   try
   {
      for (Map.Entry<CronSchedule, List<StatSync>> e: synchronizers.entrySet ())
      {
         Date next = e.getKey ().cronExpression.getNextValidTimeAfter (start);
         if (next.before (end) || next.equals (end))
         {
            res.addAll (e.getValue ());
         }
      }
   }
   finally
   {
      lockSyncMap.unlock ();
   }
   return res;
}
 
Example 3
Project: lams   File: ChatService.java   View Source Code Vote up 6 votes
@Override
   public ToolCompletionStatus getCompletionStatus(Long learnerId, Long toolSessionId) {
ChatUser learner = getUserByUserIdAndSessionId(learnerId, toolSessionId);
if (learner == null) {
    return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_NOT_ATTEMPTED, null, null);
}

Date startDate = null;
Date endDate = learner.getLastPresence();
List<ChatMessage> messages = getMessagesForUser(learner);
for ( ChatMessage message : messages ) {
    Date sendDate = message.getSendDate();
    if ( sendDate != null ) {
	if ( startDate == null || sendDate.before(startDate) )
	    startDate = sendDate;
	if ( endDate == null || sendDate.after(endDate) )
	    endDate = sendDate;
    }
}

if (learner.isFinishedActivity())
    return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_COMPLETED, startDate, endDate);
else
    return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_ATTEMPTED, startDate, null);
   }
 
Example 4
Project: DisCal-Discord-Bot   File: TimeUtils.java   View Source Code Vote up 5 votes
/**
 * Checks whether or not a date has already past (IE: March 3, 1990).
 *
 * @param dateRaw  The date to check in format (yyyy/MM/dd-HH:mm:ss).
 * @param timezone The timezone of the calendar this event is for.
 * @return <code>true</code> if the date is in the past, otherwise <code>false</code>.
 */
public static boolean inPast(String dateRaw, TimeZone timezone) {
	try {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
		sdf.setTimeZone(timezone);
		Date dateObj = sdf.parse(dateRaw);
		Date now = new Date(System.currentTimeMillis());

		return dateObj.before(now);
	} catch (ParseException e) {
		return true;
	}
}
 
Example 5
Project: uavstack   File: DateTimeHelper.java   View Source Code Vote up 5 votes
/**
 * 判断当前时间是否在在两个时间之间
 * 
 * @param startDate
 *            开始时间
 * @param endDate
 *            结束时间
 * @return
 */
public static boolean nowDateBetweenStartDateAndEndDate(Date startDate, Date endDate) {

    boolean bool = false;
    Date curDate = new Date();
    if (curDate.after(startDate) && curDate.before(endDate)) {
        bool = true;
    }
    return bool;
}
 
Example 6
Project: graphium   File: CurrentGraphVersionCacheImpl.java   View Source Code Vote up 5 votes
protected boolean checkRefreshRequired(Date cachedAt) {
	if (cachedAt == null) {
		return true;
	}
	Date now = new Date();
	Date notOlderThen = new Date(now.getTime() - refreshMetadataIfOlderThenSec
			* 1000);

	if (cachedAt.before(notOlderThen)) {
		return true;
	}
	return false;
}
 
Example 7
Project: TestDemo1-github   File: TestThread.java   View Source Code Vote up 5 votes
private static Date buildTime() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 11);//时
    calendar.set(Calendar.MINUTE, 9);//分
    calendar.set(Calendar.SECOND, 0);//秒
    Date time = calendar.getTime();
    if (time.before(new Date())) {
        //若果当前时间已经是凌晨1点后,需要往后加1天,否则任务会立即执行。
        //很多系统往往系统启动时就需要立即执行一次任务,但下面又需要每天凌晨1点执行,怎么办呢?
        //很简单,就在系统初始化话时单独执行一次任务(不需要用定时器,只是执行那段任务的代码)
        time = addDay(time, 1);
    }
    return time;
}
 
Example 8
Project: OpenHomeAnalysis   File: OhaHelper.java   View Source Code Vote up 5 votes
/**
 * Recuperar hora com minutos e segundos iguais a 59.
 * @param date informar uma data válida.
 */
public static Date getEndHour(Date date, boolean untilToday) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);

    Date dateToday = new Date();
    if (untilToday && (dateToday.before(calendar.getTime()))) {
        calendar.setTime(dateToday);
    }
    return calendar.getTime();

}
 
Example 9
Project: holon-core   File: Validator.java   View Source Code Vote up 5 votes
/**
 * Build a validator that checks that given {@link Date} value is in the future.
 * <p>
 * Supported data types: {@link Date}
 * </p>
 * @param <T> Validator type
 * @param includeTime Whether to include time in validation. If <code>false</code>, only year/month/day are
 *        considered.
 * @param message Validation error message
 * @param messageCode Optional validation error message localization code
 * @return Validator
 */
@SuppressWarnings("serial")
static <T extends Date> Validator<T> future(boolean includeTime, String message, String messageCode) {
	return new BuiltinValidator<T>() {

		@Override
		public void validate(T v) throws ValidationException {
			if (v != null) {
				if (!includeTime) {
					Date today = CalendarUtils.floorTime(Calendar.getInstance()).getTime();
					Date date = CalendarUtils.floorTime(v);
					if (today.equals(date) || date.before(today)) {
						throw new ValidationException(message, messageCode);
					}
				} else {
					if (v.getTime() <= System.currentTimeMillis()) {
						throw new ValidationException(message, messageCode);
					}
				}
			}
		}

		@Override
		public Optional<ValidatorDescriptor> getDescriptor() {
			return Optional.of(ValidatorDescriptor.builder().future().build());
		}
	};
}
 
Example 10
Project: xmanager   File: JwtTokenUtil.java   View Source Code Vote up 4 votes
private Boolean isTokenExpired(String token) {
    final Date expiration = getExpirationDateFromToken(token);
    return expiration.before(timeProvider.now());
}
 
Example 11
Project: date-helper   File: Zeitraum.java   View Source Code Vote up 4 votes
/**
 * Gibt an, ob das gegebene Datum innerhalb des Zeitraumes ist, d.h. date >= datumVon && date <= datumBis
 */
public boolean contains(Date date) {

	return !date.before(von) && !date.after(bis);
}
 
Example 12
Project: NotiCap   File: NotificationListenerService.java   View Source Code Vote up 4 votes
private static boolean isTimeBetween(String fromTime, String toTime, String nowTime) throws ParseException {
	String reg = "^([0-1][0-9]|2[0-3]):([0-5][0-9])$";
	if (fromTime.matches(reg) && toTime.matches(reg) && nowTime.matches(reg)) {
		boolean valid;

		Date startTime = new SimpleDateFormat("HH:mm", Locale.US).parse(fromTime);
		Calendar startCalendar = Calendar.getInstance();
		startCalendar.setTime(startTime);

		Date currentTime = new SimpleDateFormat("HH:mm", Locale.US).parse(nowTime);
		Calendar currentCalendar = Calendar.getInstance();
		currentCalendar.setTime(currentTime);

		Date endTime = new SimpleDateFormat("HH:mm", Locale.US).parse(toTime);
		Calendar endCalendar = Calendar.getInstance();
		endCalendar.setTime(endTime);

		if (currentTime.compareTo(endTime) < 0) {
			currentCalendar.add(Calendar.DATE, 1);
			currentTime = currentCalendar.getTime();
		}

		if (startTime.compareTo(endTime) < 0) {
			startCalendar.add(Calendar.DATE, 1);
			startTime = startCalendar.getTime();
		}

		if (currentTime.before(startTime)) {
			valid = false;
		} else {
			if (currentTime.after(endTime)) {
				endCalendar.add(Calendar.DATE, 1);
				endTime = endCalendar.getTime();
			}

			valid = currentTime.before(endTime);
		}
		return valid;
	} else {
		throw new IllegalArgumentException("Not a valid time, expecting HH:mm format");
	}
}
 
Example 13
Project: spring-jwt-starter   File: JwtTokenUtil.java   View Source Code Vote up 4 votes
private Boolean isTokenExpired(String token) {
    final Date expiration = getExpirationDateFromToken(token);
    return expiration.before(new Date());
}
 
Example 14
Project: decoy   File: TimeUtil.java   View Source Code Vote up 4 votes
public static String getTimeShowString(long milliseconds, boolean abbreviate) {
    String dataString;
    String timeStringBy24;

    Date currentTime = new Date(milliseconds);
    Date today = new Date();
    Calendar todayStart = Calendar.getInstance();
    todayStart.set(Calendar.HOUR_OF_DAY, 0);
    todayStart.set(Calendar.MINUTE, 0);
    todayStart.set(Calendar.SECOND, 0);
    todayStart.set(Calendar.MILLISECOND, 0);
    Date todaybegin = todayStart.getTime();
    Date yesterdaybegin = new Date(todaybegin.getTime() - 3600 * 24 * 1000);
    Date preyesterday = new Date(yesterdaybegin.getTime() - 3600 * 24 * 1000);

    if (!currentTime.before(todaybegin)) {
        dataString = "今天";
    } else if (!currentTime.before(yesterdaybegin)) {
        dataString = "昨天";
    } else if (!currentTime.before(preyesterday)) {
        dataString = "前天";
    } else if (isSameWeekDates(currentTime, today)) {
        dataString = getWeekOfDate(currentTime);
    } else {
        SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        dataString = dateformatter.format(currentTime);
    }

    SimpleDateFormat timeformatter24 = new SimpleDateFormat("HH:mm", Locale.getDefault());
    timeStringBy24 = timeformatter24.format(currentTime);

    if (abbreviate) {
        if (!currentTime.before(todaybegin)) {
            return getTodayTimeBucket(currentTime);
        } else {
            return dataString;
        }
    } else {
        return dataString + " " + timeStringBy24;
    }
}
 
Example 15
Project: Integrate   File: JwtTokenUtil.java   View Source Code Vote up 4 votes
private Boolean isTokenExpired(String token) {
    final Date expiration = getExpirationDateFromToken(token);
    return expiration.before(new Date());
}
 
Example 16
Project: microservices-sample-project   File: JwtTokenUtil.java   View Source Code Vote up 4 votes
private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) {
    return (lastPasswordReset != null && created.before(lastPasswordReset));
}
 
Example 17
Project: ChenYan   File: ActivityAdapter.java   View Source Code Vote up 4 votes
@Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

        if (holder instanceof NormalViewHolder) {

            final MActivity activity = activityList.get(position);
//        封面图片,日后实现
            Glide.with(context).load(activity.getPhoto().getUrl()).into(((NormalViewHolder) holder).image);
            //   ((NormalViewHolder.holderimage.setImageResource(R.drawable.banner5);
            ((NormalViewHolder) holder).title.setText(activity.getTitle());
            ((NormalViewHolder) holder).intro.setText(activity.getContent());
            if (activity.getLikeIdList() != null) {
                ((NormalViewHolder) holder).tvLike.setText(activity.getLikeIdList().size() + "");
            }
            ((NormalViewHolder) holder).tvComment.setText(activity.getCommentNum().toString());

/**
 * 实现三种报名标志的选择
 */
            if (activity.getJoinIdList() != null) {
                for (String id : activity.getJoinIdList()) {
                    if (MyApp.isLogin()) {
                        if (id.equals(BmobUser.getCurrentUser(User.class).getObjectId())) {
                            ((NormalViewHolder) holder).tvFlag.setText(R.string.joined);
                            break;
                        }
                    }
                }
            } else {
                try {
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    String datestring = dateFormat.format(new Date());
                    Date deadline = dateFormat.parse(activity.getDeadline());
                    Date currentdate = new Date();
                    if (currentdate.before(deadline) || activity.getDeadline().equals(datestring)) {
                        ((NormalViewHolder) holder).tvFlag.setText(R.string.on_join);
                    } else {
                        ((NormalViewHolder) holder).tvFlag.setText(R.string.end_join);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }


//        具体实现点击事件
            if (onItemClickListener != null) {
                ((NormalViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onItemClickListener.onClick(position);
                    }
                });
            }
        } else {

            holder.itemView.setVisibility(View.VISIBLE);
            holder.itemView.setPadding(0, 0, 0, 0);
            if (activityList.size() < PAGE_ITEM_COUNT) {
                holder.itemView.setVisibility(View.GONE);
                holder.itemView.setPadding(0, -holder.itemView.getHeight(), 0, 0);
            } else {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        holder.itemView.setVisibility(View.GONE);
                        holder.itemView.setPadding(0, -holder.itemView.getHeight(), 0, 0);

                    }
                }, 1000);
            }


        }
    }
 
Example 18
Project: remittanceparse   File: Main.java   View Source Code Vote up 4 votes
public static void main(String args[]) throws IOException, ParserException {
    if(args.length!=2)
    {
        printUsage();
        System.exit(1);
    }

    ArrayList<File> files=new ArrayList<>();
    scanForFiles(files,args[0]);
    files.sort(Comparator.comparing(File::toString));
    if(files.isEmpty())
    {
        System.err.println("No PDF files found.");
        System.exit(1);
    }

    ArrayList<RemittanceLine> lines=new ArrayList<>();
    Date minimumDate=null, maximumDate=null;
    for (File file : files) {
        System.err.println("Processing PDF " + file);
        RemittancePdf remittancePdf=new RemittancePdf(file);
        remittancePdf.parseRemittancePdf(lines);

        //Remittance PDF date covers the previous month
        final YearMonth yearMonth = YearMonth.from(
                Format.asLocalDate(remittancePdf.getRemittanceDate())).minusMonths(1);

        Date firstDay=Format.asDate(yearMonth.atDay(1));
        Date lastDay=Format.asDate(yearMonth.atEndOfMonth());

        if(minimumDate==null || firstDay.before(minimumDate))
            minimumDate=firstDay;

        if(maximumDate==null || lastDay.after(maximumDate))
            maximumDate=lastDay;
    }

    System.err.println("Processing transactions JSON " + args[1]);
    Transactions transactions = new Transactions(new File(args[1]),
            minimumDate, maximumDate);


    report(lines, transactions, minimumDate, maximumDate);
}
 
Example 19
Project: date-helper   File: Zeitraum.java   View Source Code Vote up 3 votes
/**
 * Gibt die Differenz in Milisekunden zwischen Start oder Ende dieses Zeitraumes und dem gegebenen Datum wie folgt
 * zurück:
 * <ul>
 * <li>Wenn <tt>date</tt> in diesem Zeitraum enthalten ist wird 0 zurückgegeben
 * (siehe {@link #contains(Date)})</li>
 * <li>Wenn <tt>date</tt> vor dem Beginn dieses Zeitraumes ist wird date.getTime() - von.getTime() zurückgegeben, der Rückgabewert wird
 * also negativ.</li>
 * <li>Wenn <tt>date</tt> nach dem Ende dieses Zeitraumes ist wird date.getTime() - bis.getTime() zurückgegeben, der Rückgabewert wird also
 * positiv.</li>
 * </ul>
 *
 * @param date das zu vergleichende Datum, darf nicht <code>null</code> sein.
 * @return die Differenz in Milisekunden zum Beginn oder zum Ende des Zeitraumes, oder 0 wenn <tt>date</tt> in diesem
 * Zeitaum enthalten ist.
 */
public long getDistanceFrom(Date date) {
	long returnValue = 0;
	if (date.before(von)) {
		returnValue = date.getTime() - von.getTime();
	} else if (date.after(bis)) {
		returnValue = date.getTime() - bis.getTime();
	}
	return returnValue;
}
 
Example 20
Project: javaportfolio   File: Util.java   View Source Code Vote up 2 votes
public static boolean isDateBeforeEuro(Date date) {

	return date.before(dateBeforeEuro);
}