I took a break from the GUI to work on the actual date calculating logic. I started this in a separate IntelliJ Project because I didn’t know how else to test it without re-building it and then reimporting it to Ignition every time.
I shortly realized I would really like to leverage the prebuilt system.date.* functions instead of manually doing date arithmetic (is there anything more disgusting?).
Is there a way to do that where I could run? Right now the code I’m testing looks like
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class DateCalculator {
    public DateCalculator(){}
    private Date calculateEndDate(String interval, Date curDate) {
        Date endDate = new Date();
        Calendar cal = Calendar.getInstance();
        switch(interval){
            case "All":
                cal.add(Calendar.DATE, 30);
                endDate = cal.getTime();
                break;
            case "Today":
                LocalTime midnight = LocalTime.MIDNIGHT;
                LocalDate today = LocalDate.now(ZoneId.of("US/Eastern"));
                LocalDateTime todayMidnight = LocalDateTime.of(today, midnight);
                LocalDateTime yesterdayMidnight = todayMidnight.plusDays(1);
                //This is how you convert a localdatetime to Date
                endDate = Date.from(yesterdayMidnight.atZone(ZoneId.of("US/Eastern")).toInstant());
                break;
            case "This Week":
                break;
        }
        return endDate;
    }
    private Date calculateStartDate(String interval, Date curDate) {
        Date startDate = new Date();
        switch(interval) {
            case "All":
                //Start of unix time
                startDate = new Date(0L);
                break;
            case "Today":
                LocalTime midnight = LocalTime.MIDNIGHT;
                LocalDate today = LocalDate.now(ZoneId.of("US/Eastern"));
                LocalDateTime todayMidnight = LocalDateTime.of(today, midnight);
                //This is how you convert a localdatetime to Date
                startDate = Date.from(todayMidnight.atZone(ZoneId.of("US/Eastern")).toInstant());
                break;
            case "This Week":
                break;
        }
        return startDate;
    }
    public ArrayList<Date> calculateEndPoints(String interval, Date curDate){
        ArrayList<Date> returnDates = new ArrayList();
        Date endDate = calculateEndDate(interval, curDate);
        Date startDate = calculateStartDate(interval, curDate);
        returnDates.add(startDate);
        returnDates.add(endDate);
        return returnDates;
    }
    public void printEndPoints(ArrayList<Date> endpoints, String option) {
        System.out.println("Endpoints for " + option + " selection.");
        System.out.println("Start date is " + endpoints.get(0));
        System.out.println("End date is " + endpoints.get(1));
    }
    public static void main(String[] args){
        DateCalculator dc = new DateCalculator();
        Date curDate = new Date();
        ArrayList<Date> AllEndPoints = dc.calculateEndPoints("All", curDate);
        ArrayList<Date> TodayEndPoints = dc.calculateEndPoints("Today", curDate);
        dc.printEndPoints(AllEndPoints, "All");
        dc.printEndPoints(TodayEndPoints, "Today");
    }
}
I realized quickly its becoming mess of different date time libraries right now and I am not using timzones on everything which I think the system.date does do (correct me if I am wrong) - a large part of why I would like to use them.  Also a big advantage would be to use the simpler system.date.add* and system.date.get* functions would help me do the more complicated calculations much more easily.  What would be the easiest/ most appropriate way to be able to use those functions in my testing of this DateCalculator?  FWIW the original project I made from the vision-component-archetype so I don’t know if that means the scripting functions are there or not so I don’t know if bringing this over to that would work automatically.





