How to Validate Ordinal Dates?

game warrior

My julian date is in 7 digit format YYYYDDD. I want to make sure all the scenarios of leap years should be covered. Currently I have put a check on days. Is there any utility validating it ?

Live and Let Live

I want to make sure all the scenarios of leap years should be covered. Currently I have put a check on days. Is there any utility validating it ?

Yes, simply format the strings to LocalDate using the pattern, uuuuDDD and the leap years will be automatically be taken into consideration by the parsing API.

Demo:

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        // The 100th day of the year, 2020
        String strDate1 = "2020100";

        // The 100th day of the year, 2019
        String strDate2 = "2019100";

        // Notice 'D' (day-of-year) instead of 'd' (day-of-month)
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuuDDD");

        LocalDate date1 = LocalDate.parse(strDate1, dtf);
        LocalDate date2 = LocalDate.parse(strDate2, dtf);

        System.out.println(date1);
        System.out.println(date2);
    }
}

Output:

2020-04-09
2019-04-10

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to validate the dates displayed are correct?

How to validate if two dates in array are not same with Carbon

Laravel - How to validate dates with relative formats?

How can I validate or format dates in excel

How to validate range dates with rails 6

parse dates with ordinal date fields

How can validate 3 dates in row from datepicker

How to validate that an array with dates is arranged newer to older and vice versa

How to validate dates without leading zero on day and month?

Python pydantic validate dates

CompareValidator to validate two dates

React validate mongoDB dates

How to recode ordinal variable?

Google Sheets formula to convert FROM ordinal dates TO standard dates

way to validate a set of dates in Python

How to cast an enum ordinal as a String?

How to deal with ordinal labels in keras?

How to change Ordinal Date to MMDDYYYY

How to get ordinal Numbers in flutter

How to calculate ordinal number on columns?

Format for ordinal dates (day of month with suffixes -st, -nd, -rd, -th)

How do I validate the correct date format pattern? Format patterns, not dates from strings

How can I use regex in python to validate dates in the MM/DD/YYYY format?

How to validate text input fields receiving dates such that it is between 4 and 8 weeks from today?

How do I validate between two dates using LocalTime using Springboot and Thymeleaf

How would I compare two dates in a form and validate them? The second one shouldn't be before the first one

Validate if date is in between two dates - Excel

function to validate dates using regex in bash

Validate a date is not between an array of range of dates