Module edate

edate is a date manipulation library.

Copyright © 2010 David Weldon Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Authors: David Weldon.

Description

edate is a date manipulation library.

Data Types

date()

date() = {year(), month(), day()}

day()

day() = 1..31

month()

month() = 1..12

period()

period() = day | days | week | weeks | month | months | year | years

year()

year() = non_neg_integer()

Function Index

beginning_of_month/1Returns the first date of the month containing Date.
date_to_string/1Returns an ISO 8601 representation of Date.
day_of_week/1Returns the day of the week as a string ("monday".."sunday") for Date.
easter/1Returns the date for Easter (Roman Catholic) in Year.
end_of_month/1Returns the last date of the month containing Date.
is_after/2Returns true if Date1 is after Date2, and false otherwise.
is_before/2Returns true if Date1 is before Date2, and false otherwise.
is_in_future/1Returns true if Date is in the future, and false otherwise.
is_in_past/1Returns true if Date is in the past, and false otherwise.
shift/2Returns a new date after shifting today's date by N periods.
shift/3Returns a new date after shifting Date by N periods.
string_to_date/1Converts String to a date.
subtract/2Returns Date1 - Date2 as an integer number of days.
today/0Returns today's date.
tomorrow/0Returns tomorrow's date.
yesterday/0Returns yesterday's date.

Function Details

beginning_of_month/1

beginning_of_month(X1::date()) -> date()

Returns the first date of the month containing Date.

  > edate:beginning_of_month({2010,2,15}).
  {2010,2,1}

date_to_string/1

date_to_string(X1::date()) -> string()

Returns an ISO 8601 representation of Date.

  > edate:date_to_string({1976,3,18}).
  "1976-03-18"

day_of_week/1

day_of_week(Date::date()) -> string()

Returns the day of the week as a string ("monday".."sunday") for Date.

  > edate:day_of_week({2010,7,4}).
  "sunday"

easter/1

easter(Year::year()) -> date()

Returns the date for Easter (Roman Catholic) in Year. Derived from http://www.gmarts.org/index.php?go=415#geteasterdatec.

  > edate:easter(2010).
  {2010,4,4}

end_of_month/1

end_of_month(X1::date()) -> date()

Returns the last date of the month containing Date.

  > edate:end_of_month({2010,2,15}).
  {2010,2,28}

is_after/2

is_after(Date1::date(), Date2::date()) -> boolean()

Returns true if Date1 is after Date2, and false otherwise.

  > edate:is_after({1950,7,2}, {1950,7,1}).
  true

is_before/2

is_before(Date1::date(), Date2::date()) -> boolean()

Returns true if Date1 is before Date2, and false otherwise.

  > edate:is_before({1950,7,1}, {1950,7,2}).
  true

is_in_future/1

is_in_future(Date::date()) -> boolean()

Returns true if Date is in the future, and false otherwise.

  > edate:is_in_future({3000,7,1}).
  true

is_in_past/1

is_in_past(Date::date()) -> boolean()

Returns true if Date is in the past, and false otherwise.

  > edate:is_in_past({1950,7,1}).
  true

shift/2

shift(N::integer(), Period::period()) -> date()

Returns a new date after shifting today's date by N periods.

shift/3

shift(Date::date(), N::integer(), Period::period()) -> date()

Returns a new date after shifting Date by N periods.

  > edate:shift({2000,1,1}, -2, days).
  {1999,12,30}
  > edate:shift({2010,2,27}, 1, week).
  {2010,3,6}

string_to_date/1

string_to_date(String::string()) -> date()

Converts String to a date. The following string formats are valid (with or without zero-padding): YYYY-MM-DD, YYYY/MM/DD, MM-DD-YYYY, MM/DD/YYYY.

  > edate:string_to_date("1976-03-18").
  {1976,3,18}
  > edate:string_to_date("3/18/1976").
  {1976,3,18}

subtract/2

subtract(Date1::date(), Date2::date()) -> integer()

Returns Date1 - Date2 as an integer number of days. The number of days returned will be positive if Date1 > Date2.

  > edate:subtract({2010,7,4}, {2010,7,1}).
  3
  > edate:subtract({2010,7,1}, {2010,7,4}).
  -3

today/0

today() -> date()

Returns today's date.

tomorrow/0

tomorrow() -> date()

Returns tomorrow's date.

yesterday/0

yesterday() -> date()

Returns yesterday's date.


Generated by EDoc