Chronos v1.8.0 Chronos View Source
Link to this section Summary
Functions
There is an option to supply a date. This is handy for testing
#beginning_of_week/2 function returns the date of starting day of the week for given date. It defaults to today for given date and Monday(1) for starting day of the week. Mon = 1, Tue = 2, Wed =3 , Thu = 4 , Fri = 5 , Sat = 6 , Sun = 7 If today is {2012,12,21} iex(1)> Chronos.beginning_of_week {2012,12,17} iex(2)> Chronos.beginning_of_week({2015,1,20}) {2015,1,19} iex(3)> Chronos.beginning_of_week({2015,1,20},3) {2015,1,14}
The day function allows you to extract the day from a date tuple
The following functions all have similar behavior. The days_ago/2 and weeks_ago/2 functions take a integer representing the number of days or weeks in the past and return the corresponding date. There is a optional argument for a date to base the calculation on but if no date is provided then the current date is used
#end_of_week/2 function returns the date of starting day of the week for given date. It defaults to today for given date and Sunday(7) for ending day of the week. Mon = 1, Tue = 2, Wed =3 , Thu = 4 , Fri = 5 , Sat = 6 , Sun = 7 If today is {2012,12,21} iex(1)> Chronos.end_of_week {2012,12,23} iex(2)> Chronos.end_of_week({2015,1,20}) {2015,1,25} iex(3)> Chronos.end_of_week({2015,1,20},3) {2015,1,21}
The epoch_time/1 function returns the number of seconds since January 1, 1970 00:00:00. If the date is prior to January 1, the integer will be negative
The from_epoch_time/1 function converts from epoch time to datetime tuple
The hour function allows you to extract the hour from a date/time tuple
The min function allows you to extract the minutes from a date/time tuple
The month function allows you to extract the month from a date tuple
The sec function allows you to extract the seconds from a date/time tuple
Chronos is an Elixir library for working with dates and times
The tomorrow function is based on the current date
Returns an integer representing the day of the week, 1..7, with Monday == 1
The yday function allows you to extract the day of the year (1-366) from a date tuple
The year function allows you to extract the year from a date tuple
The yesterday function is based on the current date
Link to this section Functions
There is an option to supply a date. This is handy for testing.
defmodule YourModule do
use Chronos, date: {2012, 12, 21}
end
iex(1)> YourModule.today {2012, 12, 21}
#beginning_of_week/2 function returns the date of starting day of the week for given date. It defaults to today for given date and Monday(1) for starting day of the week. Mon = 1, Tue = 2, Wed =3 , Thu = 4 , Fri = 5 , Sat = 6 , Sun = 7 If today is {2012,12,21} iex(1)> Chronos.beginning_of_week {2012,12,17} iex(2)> Chronos.beginning_of_week({2015,1,20}) {2015,1,19} iex(3)> Chronos.beginning_of_week({2015,1,20},3) {2015,1,14}
The day function allows you to extract the day from a date tuple
iex(1)> Chronos.day({2013, 8, 21}) 21
iex(2)> {2012, 12, 21} |> Chronos.day 21
The following functions all have similar behavior. The days_ago/2 and weeks_ago/2 functions take a integer representing the number of days or weeks in the past and return the corresponding date. There is a optional argument for a date to base the calculation on but if no date is provided then the current date is used.
iex(1)> Chronos.days_ago(5) {2013, 8, 16}
iex(2)> Chronos.weeks_ago(3) {2013, 3, 31}
The days_from/2 and weeks_from/2 return a future date calculated by the number of days or weeks. There is a optional argument for a date to base the calculation on but if no date is provided then the current date is used.
iex(1)> Chronos.days_from(5) {2013, 8, 26}
iex(2)> Chronos.weeks_from(3) {2013, 9, 11}
#end_of_week/2 function returns the date of starting day of the week for given date. It defaults to today for given date and Sunday(7) for ending day of the week. Mon = 1, Tue = 2, Wed =3 , Thu = 4 , Fri = 5 , Sat = 6 , Sun = 7 If today is {2012,12,21} iex(1)> Chronos.end_of_week {2012,12,23} iex(2)> Chronos.end_of_week({2015,1,20}) {2015,1,25} iex(3)> Chronos.end_of_week({2015,1,20},3) {2015,1,21}
The epoch_time/1 function returns the number of seconds since January 1, 1970 00:00:00. If the date is prior to January 1, the integer will be negative.
iex(1)> Chronos.epoch_time({2012, 12, 21}, {12, 30, 55}}
The from_epoch_time/1 function converts from epoch time to datetime tuple.
iex(1)> Chronos.from_epoch_time(1356048000)
The hour function allows you to extract the hour from a date/time tuple
iex> Chronos.hour({{2013, 8, 21}, {13, 34, 45}}) 13
iex> {{2013, 8, 21}, {13, 34, 45}} |> Chronos.hour 13
The min function allows you to extract the minutes from a date/time tuple
iex> Chronos.min({{2013, 8, 21}, {13, 34, 45}}) 34
iex> {{2013, 8, 21}, {13, 34, 45}} |> Chronos.min 34
The month function allows you to extract the month from a date tuple
iex(1)> Chronos.month({2013, 8, 21}) 8
iex(2)> {2012, 12, 21} |> Chronos.month 8
The sec function allows you to extract the seconds from a date/time tuple
iex> Chronos.sec({{2013, 8, 21}, {13, 34, 45}}) 45
iex> {{2013, 8, 21}, {13, 34, 45}} |> Chronos.sec 45
Chronos is an Elixir library for working with dates and times.
iex(1)> Chronos.today {2013, 8, 21}
The tomorrow function is based on the current date
iex(1)> Chronos.tomorrow {2013, 8, 22}
or you can pass it a date:
iex(2)> {2012, 12, 21} |> Chronos.tomorrow {2012, 12, 22}
Returns an integer representing the day of the week, 1..7, with Monday == 1.
iex(1)> Chronos.wday({2013, 8, 21}) 3
The yday function allows you to extract the day of the year (1-366) from a date tuple
iex(1)> Chronos.yday({2013, 8, 21}) 233
iex(2)> {2012, 12, 21} |> Chronos.day 356
The year function allows you to extract the year from a date tuple
iex(1)> Chronos.year({2013, 8, 21}) 2013
iex(2)> {2012, 12, 21} |> Chronos.year 2012
The yesterday function is based on the current date
iex(1)> Chronos.yesterday {2013, 8, 20}
or you can pass it a date:
iex(2)> {2012, 12, 21} |> Chronos.yesterday {2012, 12, 20}