From 30870c35f6c85faebc12b6e6ba82044241a63161 Mon Sep 17 00:00:00 2001 From: Md Riyazul Islam <121575277+Riyazul555@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:19:15 +0530 Subject: [PATCH] Date conversion Haskell program added (#5629) Co-authored-by: Riyazul555 --- ...te_format_to_julian_date_and_vice-versa.hs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 program/program/convert-standard-date-format-to-julian-date-and-vice-versa/convert_standard_date_format_to_julian_date_and_vice-versa.hs diff --git a/program/program/convert-standard-date-format-to-julian-date-and-vice-versa/convert_standard_date_format_to_julian_date_and_vice-versa.hs b/program/program/convert-standard-date-format-to-julian-date-and-vice-versa/convert_standard_date_format_to_julian_date_and_vice-versa.hs new file mode 100644 index 000000000..f8659891e --- /dev/null +++ b/program/program/convert-standard-date-format-to-julian-date-and-vice-versa/convert_standard_date_format_to_julian_date_and_vice-versa.hs @@ -0,0 +1,21 @@ +import Data.Time.Calendar +import Data.Time.Calendar.OrdinalDate + +-- Function to convert standard date format (year, month, day) to Julian date +toJulianDate :: Integer -> Int -> Int -> Day +toJulianDate year month day = fromGregorian year month day + +-- Function to convert Julian date to standard date format (year, month, day) +fromJulianDate :: Day -> (Integer, Int, Int) +fromJulianDate date = toGregorian date + +-- Example usage +main :: IO () +main = do + -- Convert standard date format to Julian date + let julianDate = toJulianDate 2024 4 9 + putStrLn $ "Julian date: " ++ show julianDate + + -- Convert Julian date to standard date format + let (year, month, day) = fromJulianDate julianDate + putStrLn $ "Standard date format: " ++ show year ++ "-" ++ show month ++ "-" ++ show day