### Install time-extra Package Source: https://context7.com/justinmimbs/time-extra/llms.txt Installs the time-extra package using the Elm package manager. This is the first step to integrating advanced time handling into your Elm application. ```bash elm install justinmimbs/time-extra ``` -------------------------------- ### Composable Time Manipulation Example Source: https://context7.com/justinmimbs/time-extra/llms.txt Demonstrates chaining multiple time-extra functions for complex time arithmetic. This example converts parts to Posix, adds two weeks, floors to the day, and converts back to parts. ```elm partsToPosix >> add Week 2 >> floor Day >> posixToParts ``` -------------------------------- ### Generate Time Ranges with Time.Extra Source: https://context7.com/justinmimbs/time-extra/llms.txt Creates a list of `Posix` times within a specified range, incrementing by a given step value at rounded intervals. The list starts on or after the first time and ends before the second time. Supports intervals like Hour, Day, and Month with various step values. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) start = Parts 2020 Jan 1 12 0 0 0 |> Time.partsToPosix utc until = start |> Time.add Day 1 utc -- Generate times every 4 hours Time.range Hour 4 utc start until == List.map (Time.partsToPosix utc) [ Parts 2020 Jan 1 12 0 0 0 , Parts 2020 Jan 1 16 0 0 0 , Parts 2020 Jan 1 20 0 0 0 , Parts 2020 Jan 2 0 0 0 0 , Parts 2020 Jan 2 4 0 0 0 , Parts 2020 Jan 2 8 0 0 0 ] -- Generate days with step of 2 start2 = Parts 2020 Jan 1 0 0 0 0 |> Time.partsToPosix utc until2 = Parts 2020 Jan 8 0 0 0 0 |> Time.partsToPosix utc Time.range Day 2 utc start2 until2 == List.map (Time.partsToPosix utc) [ Parts 2020 Jan 2 0 0 0 0 , Parts 2020 Jan 4 0 0 0 0 , Parts 2020 Jan 6 0 0 0 0 ] -- Generate months Time.range Month 2 utc (Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0)) (Time.partsToPosix utc (Parts 2000 Jul 1 0 0 0 0)) == List.map (Time.partsToPosix utc) [ Parts 2000 Jan 1 0 0 0 0 , Parts 2000 Mar 1 0 0 0 0 , Parts 2000 May 1 0 0 0 0 ] ``` -------------------------------- ### Time.Extra.toOffset Source: https://context7.com/justinmimbs/time-extra/llms.txt Gets the offset from UTC, in minutes, for a `Zone` at a specific `Posix` time. This is useful for handling time zones and daylight saving time transitions. ```APIDOC ## toOffset ### Description Get the offset from UTC, in minutes, for a `Zone` at a specific `Posix` time. Useful for handling time zones and DST transitions. ### Method `Time.toOffset` ### Parameters - `zone` (TimeZone) - The time zone for which to get the offset. - `time` (Time.Posix) - The specific time at which to determine the offset. ### Returns `Int` - The offset from UTC in minutes. ### Request Example ```elm import Time exposing (Month(..)) import Time.Extra exposing (Parts, partsToPosix, toOffset) import TimeZone -- Define time zones nyc = TimeZone.america__new_york () paris = TimeZone.europe__paris () -- Get offset for New York (EDT: -240 minutes = -4 hours) summerTime = partsToPosix nyc (Parts 2018 Sep 26 10 30 0 0) toOffset nyc summerTime == -240 -- Winter time in New York (EST: -300 minutes = -5 hours) winterTime = partsToPosix nyc (Parts 2018 Jan 1 0 0 0 0) toOffset nyc winterTime == -300 -- Paris in summer (CEST: +120 minutes = +2 hours) parisSummer = partsToPosix paris (Parts 2018 Jul 1 0 0 0 0) toOffset paris parisSummer == 120 -- UTC always returns 0 toOffset Time.utc summerTime == 0 ``` ``` -------------------------------- ### Generate List of Posix Times Source: https://github.com/justinmimbs/time-extra/blob/master/README.md Creates a list of Posix times within a specified range, incrementing by a given interval. It requires the start time, end time, interval unit, timezone, and the increment value. The function generates times from the start up to (but not including) the end time. Imports `Time` and `Time.Extra`. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..)) start = Time.Parts 2020 Jan 1 12 0 0 0 |> Time.partsToPosix utc until = start |> Time.add Day 1 utc Time.range Hour 4 utc start until == List.map (Time.partsToPosix utc) [ Time.Parts 2020 Jan 1 12 0 0 0 , Time.Parts 2020 Jan 1 16 0 0 0 , Time.Parts 2020 Jan 1 20 0 0 0 , Time.Parts 2020 Jan 2 0 0 0 0 , Time.Parts 2020 Jan 2 4 0 0 0 , Time.Parts 2020 Jan 2 8 0 0 0 ] ``` -------------------------------- ### Time.Extra.range Source: https://context7.com/justinmimbs/time-extra/llms.txt Creates a list of times, at rounded intervals, increasing by a step value, between two times. The list starts on or after the first time and ends before the second time. ```APIDOC ## range ### Description Create a list of times, at rounded intervals, increasing by a step value, between two times. The list will start on or after the first time, and end before the second time. ### Method `Time.range` ### Parameters - `interval` (Time.Extra.Interval) - The interval to use for generating times (e.g., `Hour`, `Day`, `Month`). - `step` (Int) - The number of intervals to step by. - `zone` (Time.Zone) - The time zone to use for calculations. - `start` (Time.Posix) - The starting time. - `until` (Time.Posix) - The ending time (exclusive). ### Returns `List Time.Posix` - A list of times within the specified range and interval. ### Request Example ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) start = Parts 2020 Jan 1 12 0 0 0 |> Time.partsToPosix utc until = start |> Time.add Day 1 utc -- Generate times every 4 hours Time.range Hour 4 utc start until == List.map (Time.partsToPosix utc) [ Parts 2020 Jan 1 12 0 0 0 , Parts 2020 Jan 1 16 0 0 0 , Parts 2020 Jan 1 20 0 0 0 , Parts 2020 Jan 2 0 0 0 0 , Parts 2020 Jan 2 4 0 0 0 , Parts 2020 Jan 2 8 0 0 0 ] -- Generate days with step of 2 start2 = Parts 2020 Jan 1 0 0 0 0 |> Time.partsToPosix utc until2 = Parts 2020 Jan 8 0 0 0 0 |> Time.partsToPosix utc Time.range Day 2 utc start2 until2 == List.map (Time.partsToPosix utc) [ Parts 2020 Jan 2 0 0 0 0 , Parts 2020 Jan 4 0 0 0 0 , Parts 2020 Jan 6 0 0 0 0 ] -- Generate months Time.range Month 2 utc (Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0)) (Time.partsToPosix utc (Parts 2000 Jul 1 0 0 0 0)) == List.map (Time.partsToPosix utc) [ Parts 2000 Jan 1 0 0 0 0 , Parts 2000 Mar 1 0 0 0 0 , Parts 2000 May 1 0 0 0 0 ] ``` ``` -------------------------------- ### Get TimeZone Offset with Time.Extra Source: https://context7.com/justinmimbs/time-extra/llms.txt Retrieves the offset from UTC, in minutes, for a given `Zone` at a specific `Posix` time. This function is essential for handling time zone conversions and accounting for Daylight Saving Time (DST) transitions. It returns 0 for UTC. ```elm import Time exposing (Month(..)) import Time.Extra exposing (Parts, partsToPosix, toOffset) import TimeZone -- Define time zones nyc = TimeZone.america__new_york () paris = TimeZone.europe__paris () -- Get offset for New York (EDT: -240 minutes = -4 hours) summerTime = partsToPosix nyc (Parts 2018 Sep 26 10 30 0 0) toOffset nyc summerTime == -240 -- Winter time in New York (EST: -300 minutes = -5 hours) winterTime = partsToPosix nyc (Parts 2018 Jan 1 0 0 0 0) toOffset nyc winterTime == -300 -- Paris in summer (CEST: +120 minutes = +2 hours) parisSummer = partsToPosix paris (Parts 2018 Jul 1 0 0 0 0) toOffset paris parisSummer == 120 -- UTC always returns 0 toOffset Time.utc summerTime == 0 ``` -------------------------------- ### Compare Two Posix Times for Order (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Explains the 'compare' function, which takes two 'Posix' times and returns an 'Order' value ('LT', 'EQ', or 'GT') indicating their relative order. This function is essential for sorting or conditional logic based on time. ```elm import Time import Time.Extra as Time a = Time.millisToPosix 0 b = Time.millisToPosix 1000 Time.compare a b == LT -- a is earlier than b Time.compare b a == GT -- b is later than a Time.compare a a == EQ -- same time ``` -------------------------------- ### Ceiling Time to Interval with Time.Extra Source: https://context7.com/justinmimbs/time-extra/llms.txt Rounds up a given time to the beginning of the closest specified interval. The resulting time will always be greater than or equal to the original time. If the time is already at the beginning of an interval, it returns the same time. Supports intervals like Hour, Day, and Month. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) time = Time.partsToPosix utc (Parts 1999 Dec 31 23 59 59 999) -- Ceiling to various intervals Time.ceiling Hour utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Day utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Month utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) -- If already at a round interval, returns the same time roundTime = Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Hour utc roundTime == roundTime ``` -------------------------------- ### Floor Time to Interval with Time.Extra Source: https://context7.com/justinmimbs/time-extra/llms.txt Rounds down a given time to the beginning of the closest specified interval. The resulting time will always be less than or equal to the original time. Supports intervals like Hour, Day, Month, Year, and specific weekdays like Monday. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) time = Time.partsToPosix utc (Parts 1999 Dec 31 23 59 59 999) -- Floor to various intervals Time.floor Hour utc time == Time.partsToPosix utc (Parts 1999 Dec 31 23 0 0 0) Time.floor Day utc time == Time.partsToPosix utc (Parts 1999 Dec 31 0 0 0 0) Time.floor Month utc time == Time.partsToPosix utc (Parts 1999 Dec 1 0 0 0 0) Time.floor Year utc time == Time.partsToPosix utc (Parts 1999 Jan 1 0 0 0 0) -- Floor to weekday (previous Monday) Time.floor Monday utc time == Time.partsToPosix utc (Parts 1999 Dec 27 0 0 0 0) ``` -------------------------------- ### Define Parts Record for Abstract Time Representation (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Demonstrates how to define and create 'Parts' records, which represent a time abstractly using calendar date and clock time components. These records can be converted to concrete 'Posix' moments given a time zone. The structure includes year, month, day, hour, minute, second, and millisecond. ```elm import Time exposing (Month(..)) import Time.Extra exposing (Parts) -- Parts record structure -- { year : Int, month : Month, day : Int, hour : Int, minute : Int, second : Int, millisecond : Int } -- Create a Parts record for September 26, 2018 at 2:30 PM myTime : Parts myTime = Parts 2018 Sep 26 14 30 0 0 -- Create a Parts record for New Year's Eve 1999 newYearsEve : Parts newYearsEve = Parts 1999 Dec 31 23 59 59 999 ``` -------------------------------- ### Convert Parts to Posix Time with Time Zone (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Shows how to use the 'partsToPosix' function to convert a 'Parts' record into a 'Posix' time, specifying a time zone like UTC. The function handles out-of-range day or time values by clamping them to valid ranges, ensuring a correct 'Posix' representation. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Parts) -- Create a Posix time in UTC posixTime = Time.partsToPosix utc (Parts 2018 Sep 26 14 30 0 0) -- Out-of-range values are automatically clamped -- Invalid: Sep 31, hour 24, minute 60, second -60 -- Becomes: Sep 30, hour 23, minute 59, second 0 clampedTime = Time.partsToPosix utc (Parts 2018 Sep 31 24 60 -60 -500) -- == Time.partsToPosix utc (Parts 2018 Sep 30 23 59 0 0) ``` -------------------------------- ### Time.Extra.floor Source: https://context7.com/justinmimbs/time-extra/llms.txt Rounds down a time to the beginning of the closest interval. The resulting time will be less than or equal to the one provided. Supports various intervals including `Hour`, `Day`, `Month`, `Year`, and specific weekdays. ```APIDOC ## floor ### Description Round down a time to the beginning of the closest interval. The resulting time will be less than or equal to the one provided. ### Method `Time.floor` ### Parameters - `interval` (Time.Extra.Interval) - The interval to floor to (e.g., `Hour`, `Day`, `Month`, `Year`, `Monday`). - `zone` (Time.Zone) - The time zone to use for calculations. - `time` (Time.Posix) - The time to floor. ### Returns `Time.Posix` - The floored time. ### Request Example ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) time = Time.partsToPosix utc (Parts 1999 Dec 31 23 59 59 999) -- Floor to various intervals Time.floor Hour utc time == Time.partsToPosix utc (Parts 1999 Dec 31 23 0 0 0) Time.floor Day utc time == Time.partsToPosix utc (Parts 1999 Dec 31 0 0 0 0) Time.floor Month utc time == Time.partsToPosix utc (Parts 1999 Dec 1 0 0 0 0) Time.floor Year utc time == Time.partsToPosix utc (Parts 1999 Jan 1 0 0 0 0) -- Floor to weekday (previous Monday) Time.floor Monday utc time == Time.partsToPosix utc (Parts 1999 Dec 27 0 0 0 0) ``` ``` -------------------------------- ### Time.Extra.ceiling Source: https://context7.com/justinmimbs/time-extra/llms.txt Rounds up a time to the beginning of the closest interval. The resulting time will be greater than or equal to the one provided. If the time is already at a rounded interval, it returns the same time. ```APIDOC ## ceiling ### Description Round up a time to the beginning of the closest interval. The resulting time will be greater than or equal to the one provided. ### Method `Time.ceiling` ### Parameters - `interval` (Time.Extra.Interval) - The interval to ceil to (e.g., `Hour`, `Day`, `Month`, `Year`). - `zone` (Time.Zone) - The time zone to use for calculations. - `time` (Time.Posix) - The time to ceil. ### Returns `Time.Posix` - The ceiling time. ### Request Example ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) time = Time.partsToPosix utc (Parts 1999 Dec 31 23 59 59 999) -- Ceiling to various intervals Time.ceiling Hour utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Day utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Month utc time == Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) -- If already at a round interval, returns the same time roundTime = Time.partsToPosix utc (Parts 2000 Jan 1 0 0 0 0) Time.ceiling Hour utc roundTime == roundTime ``` ``` -------------------------------- ### Create Posix Time from Parts Source: https://github.com/justinmimbs/time-extra/blob/master/README.md Constructs a Posix time value from individual date and time components (year, month, day, hour, minute, second, millisecond). It requires the `Time` module and `Time.Extra` for the `Parts` constructor and `partsToPosix` function. The `utc` function from `Time` is used to specify the timezone. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time Time.Parts 2018 Sep 26 14 30 0 0 |> Time.partsToPosix utc ``` -------------------------------- ### Convert Posix Time to Parts with Time Zone (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Demonstrates the 'posixToParts' function, which converts a 'Posix' time into a 'Parts' record for a given time zone. This is a utility function for extracting detailed date and time components from a concrete 'Posix' moment. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Parts) posixTime = Time.partsToPosix utc (Parts 2018 Sep 26 14 30 0 0) parts = Time.posixToParts utc posixTime -- == { year = 2018 -- , month = Sep -- , day = 26 -- , hour = 14 -- , minute = 30 -- , second = 0 -- , millisecond = 0 -- } ``` -------------------------------- ### Import time-extra Module Source: https://context7.com/justinmimbs/time-extra/llms.txt Imports the necessary module from the time-extra package. This allows you to use its functions in your Elm code. ```elm import Time.Extra ``` -------------------------------- ### Add Time Intervals with Time.Extra Source: https://context7.com/justinmimbs/time-extra/llms.txt Shifts a time into the past or future by adding a specified number of whole intervals. Supports various intervals like Week, Day, Month, Quarter, and Year. For Month, Quarter, and Year, day values are clamped to the end of the month if necessary. Negative numbers can be used for subtraction. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) start = Time.partsToPosix utc (Parts 2018 Sep 1 11 55 0 0) -- Add 2 weeks Time.add Week 2 utc start == Time.partsToPosix utc (Parts 2018 Sep 15 11 55 0 0) -- Adding months clamps to valid days jan31 = Time.partsToPosix utc (Parts 2020 Jan 31 0 0 0 0) Time.add Month 1 utc jan31 == Time.partsToPosix utc (Parts 2020 Feb 29 0 0 0 0) -- Subtract time by using negative numbers Time.add Day -7 utc start == Time.partsToPosix utc (Parts 2018 Aug 25 11 55 0 0) ``` -------------------------------- ### Time.Extra.add Source: https://context7.com/justinmimbs/time-extra/llms.txt Shifts a time into the past or future by adding a number of whole intervals. Handles month, quarter, and year intervals by clamping day values to the end of the month if necessary. Supports subtracting time using negative numbers. ```APIDOC ## add ### Description Shift a time into the past or future by adding a number of whole intervals. When adding `Month`, `Quarter`, or `Year` intervals, day values are clamped to the end of the month if necessary. ### Method `Time.add` ### Parameters - `interval` (Time.Extra.Interval) - The unit of time to add (e.g., `Day`, `Week`, `Month`, `Year`). - `count` (Int) - The number of intervals to add. Can be negative to subtract time. - `zone` (Time.Zone) - The time zone to use for calculations. - `time` (Time.Posix) - The starting time. ### Returns `Time.Posix` - The new time after adding the specified intervals. ### Request Example ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) start = Time.partsToPosix utc (Parts 2018 Sep 1 11 55 0 0) -- Add 2 weeks Time.add Week 2 utc start == Time.partsToPosix utc (Parts 2018 Sep 15 11 55 0 0) -- Adding months clamps to valid days jan31 = Time.partsToPosix utc (Parts 2020 Jan 31 0 0 0 0) Time.add Month 1 utc jan31 == Time.partsToPosix utc (Parts 2020 Feb 29 0 0 0 0) -- Subtract time by using negative numbers Time.add Day -7 utc start == Time.partsToPosix utc (Parts 2018 Aug 25 11 55 0 0) ``` ``` -------------------------------- ### Define Interval Types for Time Manipulation (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Illustrates the 'Interval' union type provided by 'Time.Extra'. This type represents various time intervals such as years, months, days, hours, and specific weekdays, used in functions like 'diff', 'add', 'floor', 'ceiling', and 'range'. ```elm import Time.Extra exposing (Interval(..)) -- Available intervals: -- Year, Quarter, Month, Week, Day, Hour, Minute, Second, Millisecond -- Weekday-specific: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday intervals : List Interval intervals = [ Year , Quarter , Month , Week , Day , Hour , Minute , Second , Millisecond , Monday , Tuesday , Wednesday , Thursday , Friday , Saturday , Sunday ] ``` -------------------------------- ### Calculate Difference Between Times in Intervals (Elm) Source: https://context7.com/justinmimbs/time-extra/llms.txt Details the 'diff' function, which calculates the difference between two 'Posix' times in terms of whole intervals. The result is positive if the second time is later than the first. It supports various 'Interval' types, including days, months, and weekdays. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..), Parts) time1 = Time.Parts 2020 Sep 1 12 0 0 0 |> Time.partsToPosix utc time2 = Time.Parts 2020 Sep 4 11 0 0 0 |> Time.partsToPosix utc -- Difference in days (whole intervals only) Time.diff Day utc time1 time2 == 2 -- Difference in various intervals jan = Time.partsToPosix utc (Parts 2020 Jan 2 0 0 0 0) apr = Time.partsToPosix utc (Parts 2020 Apr 1 0 0 0 0) Time.diff Month utc jan apr == 2 -- Negative differences when first time is later Time.diff Day utc time2 time1 == -2 ``` -------------------------------- ### Calculate Time Difference Source: https://github.com/justinmimbs/time-extra/blob/master/README.md Calculates the difference between two Posix times in a specified unit (e.g., Day, Hour). It takes the unit of difference, timezone, and the two Posix times as input. The result is an integer representing the number of units between the times. Requires `Time` and `Time.Extra` modules. ```elm import Time exposing (Month(..), utc) import Time.Extra as Time exposing (Interval(..)) time1 = Time.Parts 2020 Sep 1 12 0 0 0 |> Time.partsToPosix utc time2 = Time.Parts 2020 Sep 4 11 0 0 0 |> Time.partsToPosix utc Time.diff Day utc time1 time2 == 2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.