-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add TimeFormatter, prepare Futr data structure
- Loading branch information
Showing
7 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module TimeFormatter (formatDateTime) where | ||
|
||
import Data.Int (Int64) | ||
import Data.Text (Text) | ||
import Data.Text qualified as T | ||
import Data.Time (UTCTime, formatTime, defaultTimeLocale) | ||
import Data.Time.Clock.POSIX (posixSecondsToUTCTime) | ||
|
||
data Language = English | Spanish | German | ||
|
||
-- Convert Int64 (Unix timestamp) to UTCTime | ||
int64ToUTCTime :: Int64 -> UTCTime | ||
int64ToUTCTime = posixSecondsToUTCTime . fromIntegral | ||
|
||
-- Format UTCTime to Text based on the provided format | ||
formatUTCTime :: String -> UTCTime -> Text | ||
formatUTCTime format utcTime = T.pack $ formatTime defaultTimeLocale format utcTime | ||
|
||
-- Helper function to format time | ||
formatDateTime :: Language -> Int64 -> Text | ||
formatDateTime English = formatUTCTime "%H:%M:%S %Y-%m-%d" . int64ToUTCTime | ||
formatDateTime German = formatUTCTime "%H:%M:%S %d.%m.%Y" . int64ToUTCTime | ||
formatDateTime Spanish = formatUTCTime "%H:%M:%S %d/%m/%Y" . int64ToUTCTime |