DCalendar

A primitive Unix calendar implementation in D
git clone git://xatko.vsos.ethz.ch/DCalendar.git
Log | Files | Refs

commit 80622da324d9b6a6a089624e0d4b7b0240ffedd7
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Tue, 28 Jul 2015 22:09:31 +0200

Initial commit.

Diffstat:
dcalendar.d | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/dcalendar.d b/dcalendar.d @@ -0,0 +1,47 @@ +module dcalendar; +import std.stdio; +import std.algorithm; +import std.datetime; +import std.string; + +class Calendar{ + private string filename; + private File f; + private static char buf[6]; + this(string filename){ + this.filename=filename; + } + public void open(){ + f.open(filename,"r"); + } + public void close(){ + f.close(); + } + char[] format(inout ref SysTime t){ + return sformat(buf,"%02d/%02d", t.month, t.day); + } + public auto getEntries(inout SysTime t) + in{ + assert(f.isOpen, "File not open"); + } + body{ + return f.byLine.filter!(a=>startsWith(a, this.format(t))).map!(a=>a[6..$]); + } +} + +struct CalendarList{ + Calendar calendars[]; + + void add(string filename){ + calendars~=new Calendar(filename); + } + void run(inout SysTime t, void delegate(char[]) f){ + foreach(ref Calendar c; calendars){ + c.open(); + foreach(char[] s; c.getEntries(t)){ + f(s); + } + c.close(); + } + } +}