adius/vectual/5.0.0

NOTE: the latest version is 6.0.0

Renamed to ad-si/Vectual. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as adius/vectual still install under that name. 3 versions of 7 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/ad-si/Vectual.

What we checked: The repo moved to github.com/ad-si/Vectual and tag 5.0.0 is there; its commit 14ae04e1bb14 is from 2023-09-18 14:03 UTC, before the version was published (2023-09-18 14:04 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one (GitHub's zip no longer comes out byte for byte the same), so the contents were checked instead.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/adius/vectual/zipball/5.0.0/

TimeUtils.Duration

A Duration is a length of time that may vary with calendar date and time. It can be used to modify a date.

Represents a period of time expressed in human chronological terms in terms of a calendar which may have varying components based upon the dates involved in the math.

When modify dates using Durations (Day | Month | Week | Year) this module compensates for day light saving hour variations to minimize the scenarios that cause the Hour field in the result to be different to the input date. It can't completely avoid the hour changing as some hours are not a real world date and hence will modify the hour more than the Duration modified.

This behavior is modeled on moment.js so any observed behavior that is not the same as moment.js should be raised as an issue.

Note adding or subtracting 24 * Hour units from a date may produce a different answer to adding or subtracting a Day if day light saving transitions occur as part of the date change.

Warning

Be careful if you add Duration Delta to a Date as Duration contains months and Years which are not fixed elapsed times like Period Delta , however if you really need a relative number of months or years then it may meet your needs.

add : Duration -> Int -> Posix -> Posix

Add duration count to date.

= Millisecond
| Second
| Minute
| Hour
| Day
| Week
| Month
| Year
| Delta DurationDeltaRecord

A Duration is time period that may vary with with calendar and time.

Using Duration adding 24 hours can produce different result to adding 1 day.

type alias DurationDeltaRecord =
{ year : Int
, month : Int
, day : Int
, hour : Int
, minute : Int
, second : Int
, millisecond : Int
}

A multi granularity duration delta. This does not contain week like Period.DeltaRecord. It does contain month and year.

Convert a Duration to a String. Especially helpful printing debugging information.

zeroDelta : DurationDeltaRecord

All zero delta. Useful as a starting point if you want to set a few fields only.

diff : Posix -> Posix -> DurationDeltaRecord

Return a Period representing date difference date1 - date2. If you add the result of this function to date2 with addend of 1 will not always return date1, this is because this module supports human calendar concepts like Day Light Saving, Months with varying number of days dependent on the month and leap years. So the difference between two dates is dependent on when those dates are. Differences to Period.diff

  • Duration DurationDeltaRecord excludes week field
  • Duration DurationDeltaRecord includes month field
  • Duration DurationDeltaRecord includes year field
  • Day is number of days difference between months. When adding a Duration DurationDeltaRecord to a date. The larger granularity fields are added before lower granularity fields so Years are added before Months before Days etc.
  • Very different behavior to Period diff
  • If date1 > date2 then all fields in DurationDeltaRecord will be positive or zero.
  • If date1 < date2 then all fields in DurationDeltaRecord will be negative or zero.
  • Because it deals with non fixed length periods of time Example 1. days in 2016-05 (May) = 31 days in 2016-04 (Apr) = 30 days in 2016-03 (Mar) = 31 days in 2015-03 (Mar) = 31 diff of "2016-05-15" "2015-03-20" result naive field diff. year 1, month 2, day -5 days "2015-03-20" to "2015-04-01" (31 - 20) = 11 days (12). still in march with 11. days "2015-04-01" to "2016-04-15" (15 - 1) = 14 days months "2016-04-15" to "2016-05-15" 1 months result field diff year 1, month 1, day 26 This logic applies all the way down to milliseconds.
diffDays : Posix -> Posix -> Int

Returns date1 - date2 as number of days to add to date1 to get to day date2 is on. date1 - date2 in days. Only calculates days difference and ignores any field smaller than day in calculation.

addMonth : Int -> Posix -> Posix

Return a date with month count added to date. New version leveraging daysFromCivil does not loop over months so faster and only compensates at outer level for DST. Expects input in local time zone. Return is in local time zone.

addYear : Int -> Posix -> Posix

Return a date with year count added to date.

deltaToString : DurationDeltaRecord -> String

Convert a DurationDeltaRecord to a String to easily display it during testing.

positiveDiff : Posix -> Posix -> Int -> DurationDeltaRecord

Return diff between dates. It returns date1 - date2 in a DurationDeltaRecord. Precondition for this function is date1 must be after date2. Input multiplier is used to multiply output fields as needed for caller, this is used to conditionally negate them in initial use case.

positiveDiffDays : Posix -> Posix -> Int -> Int

Return number of days added to date1 to produce date2

Return true if this Duration unit compensates for crossing daylight saving boundaries. TODO: This may need to compensate for day light saving for all fields as all of them can cause the date to change the zone offset.