Skip to content

Commit

Permalink
first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Weldon committed Jul 2, 2010
0 parents commit 82e2d5f
Show file tree
Hide file tree
Showing 6 changed files with 742 additions and 0 deletions.
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Emakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ 'src/*', [{ outdir, "ebin"}]}.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
compile:
erl -make
clean:
rm -rf ebin/*.beam
test:
erl -pa "ebin" -noshell -eval "edate:test()" -s init stop
25 changes: 25 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Overview
--------
edate is an erlang date manipulation library

Installation
------------
git clone git://github.com/dweldon/edate.git
cd edate && make

Functions
---------
### today
returns the current date as {Year, Month, Day}.
> edate:today().
{2010,7,1}

### tomorrow
returns tomorrow's date as {Year, Month, Day}.
> edate:tomorrow().
{2010,7,2}

### yesterday()
returns yesterday's date as {Year, Month, Day}.
> edate:yesterday().
{2010,6,30}
1 change: 1 addition & 0 deletions ebin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.beam
35 changes: 35 additions & 0 deletions src/edate.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%% Copyright (c) 2010 David Weldon
%% This program is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>.

-module(edate).
-export([today/0, tomorrow/0, yesterday/0]).
-include_lib("eunit/include/eunit.hrl").


% @spec today() -> {Year, Month, Day}
today() -> date().

% @spec tomorrow() -> {Year, Month, Day}
tomorrow() -> shift(date(), 1, day).

% @spec yesterday() -> {Year, Month, Day}
yesterday() -> shift(date(), -1, day).

% @spec shift(Date::date(), N::integer(), Type::type()) -> {Year, Month, Day}
% type() = day | days | week | weeks | month | months | year | years
% date() = {Year, Month, Day}
shift(Date, N, days) ->
shift(Date, N, day);
shift(Date, N, day) ->
calendar:gregorian_days_to_date(calendar:date_to_gregorian_days(Date) + N).

0 comments on commit 82e2d5f

Please sign in to comment.