paiza.ioでelixir その247

# 概要
paiza.ioでelixirやってみた。
dateやってみた。

# サンプルコード

```

date = ~D[2000-01-01]
date.year
|> IO.inspect

date.month
|> IO.inspect

Date.diff(~D[2010-04-17], ~D[1970-01-01])
|> IO.inspect

Date.add(~D[1970-01-01], 14716)
|> IO.inspect

Date.add(~D[2000-01-03], -2)
|> IO.inspect
Date.add(~D[2000-01-01], 2)
|> IO.inspect
Date.add(~N[2000-01-01 09:00:00], 2)
|> IO.inspect
Date.add(~D[-0010-01-01], -2)
|> IO.inspect

Date.beginning_of_month(~D[2000-01-31])
|> IO.inspect
Date.beginning_of_month(~D[2000-01-01])
|> IO.inspect
Date.beginning_of_month(~N[2000-01-31 01:23:45])
|> IO.inspect

Date.beginning_of_week(~D[2020-07-11])
|> IO.inspect
Date.beginning_of_week(~D[2020-07-06])
|> IO.inspect
Date.beginning_of_week(~D[2020-07-11], :sunday)
|> IO.inspect
Date.beginning_of_week(~D[2020-07-11], :saturday)
|> IO.inspect
Date.beginning_of_week(~N[2020-07-11 01:23:45])
|> IO.inspect

Date.compare(~D[2016-04-16], ~D[2016-04-28])
|> IO.inspect
Date.compare(~D[2016-04-16], ~N[2016-04-28 01:23:45])
|> IO.inspect
Date.compare(~D[2016-04-16], ~N[2016-04-16 01:23:45])
|> IO.inspect
Date.compare(~N[2016-04-16 12:34:56], ~N[2016-04-16 01:23:45])
|> IO.inspect

#Date.convert(~D[2000-01-01], Calendar.Holocene)
#|> IO.inspect

#Date.convert!(~D[2000-01-01], Calendar.Holocene)
#|> IO.inspect

Date.day_of_era(~D[0001-01-01])
|> IO.inspect

Date.day_of_era(~D[0000-12-31])
|> IO.inspect

Date.day_of_week(~D[2016-10-31])
|> IO.inspect
Date.day_of_week(~D[2016-11-01])
|> IO.inspect
Date.day_of_week(~N[2016-11-01 01:23:45])
|> IO.inspect
Date.day_of_week(~D[-0015-10-30])
|> IO.inspect

Date.day_of_week(~D[2016-10-31], :sunday)
|> IO.inspect
Date.day_of_week(~D[2016-11-01], :sunday)
|> IO.inspect
Date.day_of_week(~N[2016-11-01 01:23:45], :sunday)
|> IO.inspect
Date.day_of_week(~D[-0015-10-30], :sunday)
|> IO.inspect

Date.day_of_year(~D[2016-01-01])
|> IO.inspect
Date.day_of_year(~D[2016-11-01])
|> IO.inspect
Date.day_of_year(~D[-0015-10-30])
|> IO.inspect
Date.day_of_year(~D[2004-12-31])
|> IO.inspect

Date.days_in_month(~D[1900-01-13])
|> IO.inspect
Date.days_in_month(~D[1900-02-09])
|> IO.inspect
Date.days_in_month(~N[2000-02-20 01:23:45])
|> IO.inspect

Date.diff(~D[2000-01-03], ~D[2000-01-01])
|> IO.inspect
Date.diff(~D[2000-01-01], ~D[2000-01-03])
|> IO.inspect
Date.diff(~D[0000-01-02], ~D[-0001-12-30])
|> IO.inspect
Date.diff(~D[2000-01-01], ~N[2000-01-03 09:00:00])
|> IO.inspect

Date.end_of_month(~D[2000-01-01])
|> IO.inspect
Date.end_of_month(~D[2000-01-31])
|> IO.inspect
Date.end_of_month(~N[2000-01-01 01:23:45])
|> IO.inspect

Date.end_of_week(~D[2020-07-11])
|> IO.inspect
Date.end_of_week(~D[2020-07-05])
|> IO.inspect
Date.end_of_week(~D[2020-07-06], :sunday)
|> IO.inspect
Date.end_of_week(~D[2020-07-06], :sunday)
|> IO.inspect
Date.end_of_week(~D[2020-07-06], :saturday)
|> IO.inspect
Date.end_of_week(~N[2020-07-11 01:23:45])
|> IO.inspect

Date.from_erl({2000, 1, 1})
|> IO.inspect
Date.from_erl({2000, 13, 1})
|> IO.inspect

Date.from_erl!({2000, 1, 1})
|> IO.inspect
#Date.from_erl!({2000, 13, 1})
#|> IO.inspect

Date.from_gregorian_days(1)
|> IO.inspect
Date.from_gregorian_days(730_485)
|> IO.inspect
Date.from_gregorian_days(-1)
|> IO.inspect

Date.from_iso8601("2023-07-23")
|> IO.inspect

Date.from_iso8601("2015:01:23")
|> IO.inspect

Date.from_iso8601("2023-07-32")
|> IO.inspect

Date.from_iso8601!("2015-01-23")
|> IO.inspect
#Date.from_iso8601!("2015:01:23")
#|> IO.inspect

Date.leap_year?(~D[2000-01-01])
|> IO.inspect
Date.leap_year?(~D[2001-01-01])
|> IO.inspect
Date.leap_year?(~D[2004-01-01])
|> IO.inspect
Date.leap_year?(~D[1900-01-01])
|> IO.inspect
Date.leap_year?(~N[2004-01-01 01:23:45])
|> IO.inspect

Date.months_in_year(~D[1900-01-13])
|> IO.inspect

Date.new(2000, 1, 1)
|> IO.inspect
Date.new(2000, 13, 1)
|> IO.inspect
Date.new(2000, 2, 29)
|> IO.inspect

Date.new(2000, 2, 30)
|> IO.inspect
Date.new(2001, 2, 29)
|> IO.inspect

Date.new!(2000, 1, 1)
|> IO.inspect
#Date.new!(2000, 13, 1)
#|> IO.inspect
Date.new!(2000, 2, 29)
|> IO.inspect

Date.quarter_of_year(~D[2016-10-31])
|> IO.inspect
Date.quarter_of_year(~D[2016-01-01])
|> IO.inspect
Date.quarter_of_year(~N[2016-04-01 01:23:45])
|> IO.inspect
Date.quarter_of_year(~D[-0015-09-30])
|> IO.inspect

Date.range(~D[1999-01-01], ~D[2000-01-01])
|> IO.inspect

range = Date.range(~D[2001-01-01], ~D[2002-01-01])
Enum.count(range)
|> IO.inspect
Enum.member?(range, ~D[2001-02-01])
|> IO.inspect
Enum.take(range, 3)
|> IO.inspect

range = Date.range(~D[2001-01-01], ~D[2002-01-01], 2)
|> IO.inspect
Enum.count(range)
|> IO.inspect
Enum.member?(range, ~D[2001-01-03])
|> IO.inspect
Enum.take(range, 3)
|> IO.inspect

Date.to_erl(~D[2000-01-01])
|> IO.inspect

Date.to_erl(~N[2000-01-01 00:00:00])
|> IO.inspect

Date.to_gregorian_days(~D[0000-01-02])
|> IO.inspect
Date.to_gregorian_days(~D[2000-01-01])
|> IO.inspect
Date.to_gregorian_days(~N[2000-01-01 00:00:00])
|> IO.inspect

Date.to_iso8601(~D[2000-02-28])
|> IO.inspect

Date.to_iso8601(~D[2000-02-28], :basic)
|> IO.inspect

Date.to_iso8601(~N[2000-02-28 00:00:00])
|> IO.inspect

Date.to_string(~D[2000-02-28])
|> IO.inspect
Date.to_string(~N[2000-02-28 01:23:45])
|> IO.inspect
Date.to_string(~D[-0100-12-15])
|> IO.inspect

date = Date.utc_today()
|> IO.inspect
date.year >= 2016
|> IO.inspect

Date.year_of_era(~D[0001-01-01])
|> IO.inspect
Date.year_of_era(~D[0000-12-31])
|> IO.inspect
Date.year_of_era(~D[-0001-01-01])
|> IO.inspect



```

# 実行結果

```
2000
1
14716
~D[2010-04-17]
~D[2000-01-01]
~D[2000-01-03]
~D[2000-01-03]
~D[-0011-12-30]
~D[2000-01-01]
~D[2000-01-01]
~D[2000-01-01]
~D[2020-07-06]
~D[2020-07-06]
~D[2020-07-05]
~D[2020-07-11]
~D[2020-07-06]
:lt
:lt
:eq
:eq
{1, 1}
{1, 0}
1
2
2
3
2
3
3
4
1
306
303
366
31
28
29
2
-2
3
-2
~D[2000-01-31]
~D[2000-01-31]
~D[2000-01-31]
~D[2020-07-12]
~D[2020-07-05]
~D[2020-07-11]
~D[2020-07-11]
~D[2020-07-10]
~D[2020-07-12]
{:ok, ~D[2000-01-01]}
{:error, :invalid_date}
~D[2000-01-01]
~D[0000-01-02]
~D[2000-01-01]
~D[-0001-12-31]
{:ok, ~D[2023-07-23]}
{:error, :invalid_format}
{:error, :invalid_date}
~D[2015-01-23]
true
false
true
false
true
12
{:ok, ~D[2000-01-01]}
{:error, :invalid_date}
{:ok, ~D[2000-02-29]}
{:error, :invalid_date}
{:error, :invalid_date}
~D[2000-01-01]
~D[2000-02-29]
4
1
2
3
#DateRange<~D[1999-01-01], ~D[2000-01-01]>
366
true
[~D[2001-01-01], ~D[2001-01-02], ~D[2001-01-03]]
#DateRange<~D[2001-01-01], ~D[2002-01-01], 2>
183
true
[~D[2001-01-01], ~D[2001-01-03], ~D[2001-01-05]]
{2000, 1, 1}
{2000, 1, 1}
1
730485
730485
"2000-02-28"
"20000228"
"2000-02-28"
"2000-02-28"
"2000-02-28"
"-0100-12-15"
~D[2023-08-19]
2016
{1, 1}
{1, 0}
{2, 0}
```

# 成果物

https://paiza.io/projects/5JR-hf--dBdyp0uOnvZNDg

以上。