Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Date conversion Haskell program added (#5629)
Browse files Browse the repository at this point in the history
Co-authored-by: Riyazul555 <riyazulislam2003@gmail.com>
  • Loading branch information
Riyazul555 and MdRiyazulIslam authored Apr 11, 2024
1 parent af1235f commit 30870c3
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 30870c3

Please sign in to comment.