A "sorta-port" of the Unix cal
command to Elm. Outputs a "calendar grid" data structure that is very useful for
creating datepickers, planners, and other UI widgets that are based around calendar months.
fromDate : Maybe Config -> Date -> List (List CalendarDate)
A version of the fromTime
function that accepts a
Date.
import Calendar exposing (fromDate)
import Date exposing (fromCalendarDate)
import Time exposing (Month(..))
july14th2020 =
fromCalendarDate 2020 Jul 14
july14th2020calendar =
fromDate Nothing july14th2020
fromTime : Maybe Config -> Time.Zone -> Time.Posix -> List (List CalendarDate)
Outputs a calendar using a Posix time. A calendar is a List representing a Month, with each item being a List of Dates representing individual weeks. Each week is always 7 day exactly, padded with dates from the previous or next month if that span of week dates overlaps with another month. This padding is useful for creating most traditional calendar displays.
import Calendar exposing (fromTime)
import Time exposing (Posix, millisToPosix, utc)
july14th2020 =
millisToPosix 1594725024442
july14th2020calendar =
fromTime Nothing utc july14th2020
{ dayDisplay : String
, weekdayNumber : Basics.Int
, date : Date
}
The data structure used to represent individual "squares" on the calendar.
A placeholder date will have a dayDisplay
value of " "
and it's .date
will be the
month for which that week overflows from/into.
{ startWeekday : Time.Weekday }
Optional configuration for the fromTime
and fromDate
functions. Can be
used to configure the starting weekday number for each "Week row" of the calendar output.
Utilizes the "Weekday" type from elm/time
import Calendar exposing (fromTime)
import Time exposing (Posix, millisToPosix, utc, Weekday(..))
july14th2020 =
millisToPosix 1594725024442
startOnMonday =
fromTime
(Just { startWeekday = Mon })
utc
july14th2020
print : List (List CalendarDate) -> String
Prints out a string representation of the calendar. For example, July 2020 (starting on Sunday):
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
This really isn't useful for anything but it felt obligatory to include given the source of inspiration for this package.