Java unit test Same day judgment ArDate, Date, Calendar, long ignore the time and judge whether they are the same day

Table of Contents ⇒ Java Unit Test Library-Artery-Sample

Q05_02.java


package jp.avaj.lib.test;

import java.util.Date;

import jp.avaj.lib.algo.ArDate;
import jp.avaj.lib.algo.ArDateUtil;

/**
Java Unit Test Same Day Judgment ArDate,Date,Calendar,Determine if long is the same day, ignoring the time

・ This sample shows a sample that compares ArDate and Date, but any combination of the above can be compared..
・ Note, ArDate holds only the date and does not handle the time..
*/
public class Q05_02 {
  public static void main(String[] args) {
    //Start a test case.
    ArTest.startTestCase("Q05_02");

    //On the day
    ArDate arDate0 = new ArDate();
    //On the day, at the time
    Date date1 = new Date();
    //If you compare this, the same day
    ArTest.sameDate("ArDate vs Date","arDate0",arDate0,"date1",date1);

    //Advance date1 by one hour, argument is day → hour → minute, this method is Calendar,Can also be used with long.
    date1 = ArDateUtil.forward(date1,0,1,0,0);
    // (If you run this test before 23:00)Same day
    ArTest.sameDate("ArDate vs Date","arDate0",arDate0,"date1",date1);

    //Advance arDate0 for a day
    arDate0.forward(1);
    //If you compare both, they are not on the same day
    ArTest.notSameDate("ArDate vs Date","arDate0",arDate0,"date1",date1);

    //Advance date1 by one day,
    date1 = ArDateUtil.forward(date1,1,0,0,0);
    //It will be the same day again
    ArTest.sameDate("ArDate vs Date","arDate0",arDate0,"date1",date1);
    //
    //End the test case
    ArTest.endTestCase();
  }
}


The result is as follows

result.txt


**** Q05_02 start ****
OK ArDate vs Date:arDate0=2019/10/23:date1=2019/10/23 06:37:09
OK ArDate vs Date:arDate0=2019/10/23:date1=2019/10/23 07:37:09
OK ArDate vs Date:arDate0=2019/10/24:date1=2019/10/23 07:37:09
OK ArDate vs Date:arDate0=2019/10/24:date1=2019/10/24 07:37:09
**** Q05_02 summary ****
test count = 4
success    = 4

Recommended Posts

Java unit test Same day judgment ArDate, Date, Calendar, long ignore the time and judge whether they are the same day
Java unit test Judgment of specified day of the week Determines whether ArDate, Date, Calendar, and long are specified days of the week.
Java Unit Test Library-Determine if Artery-Date, Calendar, long is the current date and time (specify tolerance in minutes)
Java Unit Test Library-Artery-Current Date Judgment
[Java] Method call error when inheritance and interface implementation are performed at the same time
What is the LocalDateTime class? [Java beginner] -Date and time class-
[Java] Use ResolverStyle.LENIENT to handle the date and time nicely
The relationship between strict Java date checking and daylight savings time