0

I have two string values in my benchmark test in Eclipse. Provided that one of them is empty. Users can be used to log in and log out.

I want to assign a null value as not every User has a departure date.
I will use my engineering work in sail point software.

ECLIPSE

public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        DateTimeFormatter sdf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        String tarihEnd= null; 
        String tarihStart = "18/01/2023";
        
       try {
        if  (tarihEnd !=null || tarihStart!=null)
        {
            
            LocalDate jobLeavingDay = LocalDate.parse(tarihEnd,sdf);
            LocalDate jobStartingDay = LocalDate.parse(tarihStart,sdf);
            
                 LocalDateTime beginDate = jobLeavingDay.atTime(8, 00);
                 LocalDateTime endDate = jobLeavingDay.atTime(16, 30);
                 LocalDateTime nowDateTime = LocalDateTime.now();
                
            if(nowDateTime.compareTo(beginDate)==1 && nowDateTime.compareTo(endDate)==-1) 
                      System.out.println("False1");
            
                else if(jobLeavingDay.compareTo(nowDateTime.toLocalDate())<0 && jobStartingDay.compareTo(nowDateTime.toLocalDate())<0) // jobleaving and jobstarting < nowdatetime = true
                    System.out.println("True1");

                else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())<0 && jobLeavingDay.compareTo(nowDateTime.toLocalDate()) >0) 
                    System.out.println("False2");
            
                else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())>0)
                    System.out.println("True");
            
                else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())<0)
                    System.out.println("False3"); //jobleaving null, jobStarting_NowDate den once gelirse
        }} catch (Exception e) {
            
              tarihStart=null;
               tarihEnd=null;
            
            }     
    }
}

SAILPOINT

Identification is done here. Extracts information from csv file.

Example: The actual value of the user who will start work on 20/12/2022 should be true.

But even if I put the > sign or give isAfter it gets false value every time.

What is the point to be edited here?

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import sailpoint.object.*;

DateTimeFormatter sdf= DateTimeFormatter.ofPattern("dd/MM/yyyy");

Attributes attrs = link.getAttributes();
String tarih = attrs.getString("JobLeaveDate");
String tarih2 = attrs.getString("JobStartDate");

try{
if(tarih!=null || tarih2!=null {

LocalDate jobLeavingDay = LocalDate.parse(tarih, sdf);
LocalDate jobStartingDay = LocalDate.parse(tarih2, sdf);
LocalDate nowDate = LocalDate.now();

         //LocalDateTime beginDate = jobLeavingDay.atTime(8, 00);
        // LocalDateTime endDate = jobLeavingDay.atTime(16, 30);
                // LocalDateTime nowDateTime = LocalDateTime.now();

if (jobStartingDay.compareTo(nowDate)>0)
stat="True";

else if (jobStartingDay.compareTo(nowDate)<0)
stat="False";
} } catch (Exception e) {
  
           tarih=null;
        }   
return (stat)  
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614

1 Answers1

0

With your first code. It was exception because tarihEnd = null, but you also use it that line:

LocalDate jobLeavingDay = LocalDate.parse(tarihEnd,sdf);

With yout code second, please you provide value tarih, tarih2.

Bellow my code:

 public static void main(String[] args) {
    DateTimeFormatter sdf = DateTimeFormatter.ofPattern("dd/MM/yyyy");

    String tarihEnd = "26/08/2022";
    String tarihStart = "18/01/2023";
    String stat = "";
    try {
        if (tarihEnd != null || tarihStart != null) {
            LocalDate jobLeavingDay = LocalDate.parse(tarihEnd, sdf);
            LocalDate jobStartingDay = LocalDate.parse(tarihStart, sdf);
            LocalDate nowDate = LocalDate.now();

            if (jobStartingDay.isAfter(nowDate)) {
                stat = "True";
            } else if (jobStartingDay.compareTo(nowDate) < 0)
                stat = "False";
            }
    } catch (Exception e) {
        tarihStart = null;
        tarihEnd = null;
    }
    System.out.println(stat);
}

Bellow code in library:

public boolean isAfter(ChronoLocalDate other) {
    if (other instanceof LocalDate) {
        return this.compareTo0((LocalDate)other) > 0;
    } else {
        return super.isAfter(other);
    }
}

and:

int compareTo0(LocalDate otherDate) {
    int cmp = this.year - otherDate.year;
    if (cmp == 0) {
        cmp = this.month - otherDate.month;
        if (cmp == 0) {
            cmp = this.day - otherDate.day;
        }
    }

    return cmp;
}

As you can see, we use LocalDate, so that method isAfter will return: this.compareTo0((LocalDate)other) > 0; here other = now()

My code, jobStartingDay = 18/01/2023, then cmp = 2023-2022=1, therefore isAfter = true. 18/01/2023 is the date after the today, isAfter = true is correct. Easier you should convert to long and work.

hungtv
  • 94
  • 4