All notable changes to this project will be documented in this file (at least to the extent possible, I am not infallible sadly). This project adheres to Semantic Versioning.
- Fix #214 - Permit any valid datetime type in formatting API
- Fix #215 - Properly validate 2-digit years
- Duration.scale/2 now works with float coefficients
- Implementation of Timex.Protocol for Map. This is primarily useful (and intended) for dealing with deserialized date/time structs.
- Precision calculation for microseconds was sometimes incorrect.
- Added parsing for ISO-8601 durations to the Duration API
- #206 - Bug in shifting DateTimes
- #199 - Handling of timezone names with
-
was broken.
- Add Duration.to_time/1, to_time!/1, from_time/1 for conversions to/from Time
- Converting a NaiveDateTime with to_datetime did not include microseconds
- now/0, now/1, local/0 were not microsecond precise
Duration.to_clock/1
- convert a Duration to a{hour,min,sec,usec}
tupleDuration.from_clock/1
- convert a{hour,min,sec,usec}
tuple to a Duration
IMPORTANT: This release is a significant rewrite of Timex's internals as well as API. Many things have remained unchanged, but there are many things that have as well. Mostly the removal of prior deprecations, and the removal (without deprecation) of things incompatible with, or now redundant due to, the introduction of calendar types in Elixir 1.3 and their impact on Timex. The list of these changes will be comprehensively spelled out below, along with recommendations for alternatives in the cases of removals.
Timex.Protocol
(defines the API all calendar types must implement to be used with Timex)compare/3
,diff/3
shift/2
, now allow the use of:milliseconds
and:microseconds
set/2
now allow the use of:microsecond
Timex.Duration
to_gregorian_microseconds/1
, converts a date/time value to microseconds since year zero
- Timex's old Date/DateTime types are replaced by Elixir 1.3's new calendar types, NaiveDateTime is now used where appropriate, and AmbiguousDateTime remains in order to handle timezone ambiguities.
Timex.diff/3
now returns to it's old behaviour of returning a signed integer for values, so that diffing/comparing can be done on a single value.- Renamed
Timex.Time
toTimex.Duration
to better reflect it's purpose and prevent conflicts with Elixir's built-inTime
type. - Renamed
Timex.Format.Time.*
toTimex.Format.Duration.*
- Renamed
:timestamp
options to:duration
- Renamed
*_timestamp
functions to*_duration
- Changed
Timex.Duration
to operate on and returnDuration
structs rather than Erlang timestamp tuples - Changed
Duration.from/2
, toDuration.from_*/1
, moving the unit into the name. - Renamed
to_erlang_datetime
toto_erl
- Timex.Date (use
Timex
now) - Timex.DateTime (use
Timex
now) - Timex.Convertable (no longer makes sense in the face of differentiating NaiveDateTime/DateTime)
set/2
no longer allow the use of:millisecond
- Removed
Timex.date
- Deprecated
Timex.datetime
- Removed
from_timestamp
functions - Removed
to_gregorian
- Removed
to_seconds/2
in favor ofto_gregorian_seconds/1
andto_unix/1
- Removed
normalize/1
, it no longer is necessary.normalize/2
still exists however
- Some behaviour around shifting across DST boundaries was behaving incorrectly (#142)
This release adds the base for locale-awareness in Timex, including one locale ("ru"), support for formatting datetimes in another locale, and functions which return names of things will now use the default locale. To configure Timex's default locale, put the following in config.exs:
config :timex, default_locale: "ru" # or whatever locale you want
- The ability to configure a default locale (the default is "en" if no config is provided) for formatting/translation of strings
- The ability to format a string using a given locale, otherwise the default locale is used
- Translations for the "ru" locale, more to come
- Locale awareness throughout the core API, so functions such as
day_name
will return the day name in the configured locale, if translations for that locale were provided Timex.lformat
, andTimex.lformat!
variants of the formatting functions, which take a locale to use in formatting- Added a relative time formatter, which functions very similarily to Moment.js's relative time formatting
You can use it with
Timex.format!
orTimex.format
, by providing :relative as the formatter, and using the{relative}
token in your format string. NOTE: The relative formatter does not support other tokens, only{relative}
for now, if it seems like there is a use case where{relative}
should support other tokens, I'll consider adding that. - Added
Timex.from_now
, which takes:- A single Convertable, which returns the relative time between that date/time value and now
- Two Convertables, which returns the relative time between the first date/time value, and the reference date (provided as the 2nd)
- Two variants of the above which also take a locale as the last argument, and results in the string being translated to that locale
- Added ASN.1 parsing/formatting support
- All functions which return strings, and all formatting functions, will use the default locale for translation, which is "en" unless another was configured, or one was provided if the function takes a locale as an argument.
- Milliseconds should be able to be fractional - the is_millisecond guard was only allowing integers
- Implementations of the Inspect protocol for Date, DateTime, AmbiguousDateTime, TimezoneInfo, and AmbiguousTimezoneInfo
- When inspecting any Timex types, the compact view will be used, pass structs: false to view the raw data structures if needed.
- Two new protocols,
Timex.Comparable
andTimex.Convertable
, implementing these two for your own date/time types will allow you to use the Timex API with your own types, just be aware that only Dates, DateTimes, or AmbiguousDateTimes will be returned as date/time representations, but it should be trivial to add a function in your implementation to convert back. - Basic Julian calendar implementation, which allows you to get the Julian date for a given Convertable, see
Timex.to_julian/1
, you can also get the day of the week number for a Julian date, viaTimex.Calendar.Julian
to_julian
function to theTimex.Convertable
protocolTimex.timezones
to get a list of all valid timezones
- POTENTIALLY BREAKING The
{Zname}
format token was formatting with the abbreviation, which is incorrect. It has been changed to format with the full name, use{Zabbr}
if you want the abbreviation. - Moved comparison and diffing behaviour into a new protocol,
Timex.Comparable
, which allows you to now provide your own implementations for comparing other date or datetime types against Timex ones. This makes the API more flexible, and also cleaned up the code quite a bit. - Modified Timex API to accept Comparables for just about all functions
- Added implementations of
Timex.Comparable
forTuple
,Date
,DateTime
,AmbiguousDateTime
- Added implementations of
Timex.Convertable
forMap
andAtom
. The former will accept any map with either DateTime-like keys (i.e. year/month/day/hour/minute/etc.) as strings or atoms, or any Date-like keys (year/month/day), as strings or atoms. The latter will accept only two atoms which represent Dates/DateTimes right now, :epoch, and :zero. - Modified
Timex.Comparable
to take anyTimex.Convertable
- A number of performance enhancements due to refactoring for
Convertable
andComparable
, particularly with diffing - The
%Z
strftime format token was formatting timezones as abbreviations, which is not round-trippable due to timezone ambiguity. This token now formats using the full timezone name, which is valid according to the strftime standard. - The
{Zname}
token had the same problem as above, and has been fixed to use the full name
READ THIS: This release contains breaking changes from the previous API. The changes are easy to make, and the compiler will catch almost all of them. See the Migrating section of the README for details on migrating to 2.0
- New
Date
type, which is basically the same asDateTime
, but without time/timezone, which works with most all API functions that work with DateTimes, except those which are specific to time or timezones. Functions which take a Date or DateTime and options which can manipulate both date and time properties, likeset
orshift
will work as you'd expect with Date values and time-based properties (setting a time property will change nothing, shifting will work for values which represent at least a day, sub-day values will not change the Date). - New
AmbiguousDateTime
type which is returned instead ofDateTime
when the datetime in question falls in an ambiguously defined timezone period. This type contains two fields,:before
and:after
which contain theDateTime
values to choose from. This handles cases where previously an error would likely have been thrown, or the behaviour would've been undefined. - Timex.date and Timex.datetime, which are the equivalent of the old Date.from, except produce a Date or DateTime respectively.
The
from
API still exists in the Date and DateTime modules, and is present in the Timex API for easier migration, but will be deprecated in the future. - New
from_erl
,from_timestamp
,from_microseconds
,from_milliseconds
,from_seconds
,from_days
functions to replace the oldfrom
API, and to match theTime
API more closely. - to_date/to_datetime/to_unix/to_timestamp/to_gregorian_seconds conversions in Timex.Convertable (old Timex.Date.Convert protocol)
- before?/after?/between? functions to Timex module
- format/format!/format_time/format_time!/parse/parse! API to Timex module
- week_of_month/1 and /3 to get the week index of the month a date occurs in
Timex.diff(this, other, :calendar_weeks)
- get the diff between two dates in terms of weeks on the calendar, in other words, the diff is done based on the start of the earliest date's week, and the end of the latest date's week
- BREAKING All non-bang functions in the API now return error tuples of the form
{:error, term}
instead of raising exceptions - BREAKING All DateTime-related APIs can now return an
AmbiguousDateTime
, which must be handled by choosing which DateTime to use. - BREAKING All Timezone lookups can now return an
AmbiguousTimezoneInfo
struct, which must be handled by choosing which TimezoneInfo to use. - BREAKING DateTime.ms is now DateTime.millisecond
- BREAKING Date module API has moved to Timex module
- Date and DateTime modules now contain their respective implementations of the Timex API, all shared functions have moved to the Timex module. You can work with Date or DateTimes either through the Timex API, or through the API exposed in the Date and DateTime modules. It is recommended to use Timex though.
- BREAKING Renamed Timex.Date.Convert to Timex.Convertable
- BREAKING
diff/3
now returns the same value no matter which order the arguments are given. Usecompare/3
to get the ordering
Timex.from
(oldDate.from
) variants. UseTimex.date
,Timex.datetime
,Date.from_<type>
, orDateTime.from_<type>
instead.DateTime.from
. UseTimex.datetime
,DateTime.from_erl
,DateTime.from_<type>
to_usecs
,to_msecs
,to_secs
, andto_mins
in favor ofto_microseconds
,to_milliseconds
,to_seconds
, andto_minutes
- Abbreviated unit names like
secs
ormins
,sec
ormin
, in favor of their full names (i.e.seconds
,minutes
, etc.)
- DateConvert/DateFormat aliases
- Shifting datetimes is now far more accurate than it was previously, and handles timezone changes, ambiguous timezone periods, and non-existent time periods (such as those during a timezone change like DST).
- Diffing by weeks, months, and years is now much more precise
- Humanized Time formatter now pluralizes units correctly
BREAKING: If you previously depended on parsing of timezone abbreviations for non-POSIX zones, for example, CEST, you will need to update your code to manually map that abbreviation to a valid zone name. Timezone abbreviations are only supported if they are POSIX timezones in the Olson timezone database.
- Added CHANGELOG
- Add Date.from clause to handle Phoenix datetime_select changeset
- Timezone abbreviation handling is now only valid for POSIX/Olson timezone names.
- Some small optimizations
- N/A
- Timezone abbreviation handling for non-POSIX/Olson timezone names
- Timezone abbreviation handling (was previously non-deterministic/incorrect)
- Disable tzdata's auto-update during compilation
- Usage of imperative if