ndp.lua

changeset 1
29a492373a7c
parent 0
44416491923e
child 5
3eee607e57e8
--- a/ndp.lua	Sun Jun 21 17:42:50 2009 +0100
+++ b/ndp.lua	Sun Jun 21 17:55:38 2009 +0100
@@ -77,6 +77,19 @@
 	return os.time(split_time);
 end
 
+local function find_next_day_by_name(time, day_name)
+	day_name = day_name:lower():gsub("^.", string.upper); -- Normalize
+	
+	for i=1,8 do
+		time = time + seconds_in_a.day;
+		if os.date("%A", time) == day_name then
+			return time;
+		end
+	end
+	
+	return;
+end
+
 function when(str, relative_to)
 	local time = relative_to or os.time();
 	local P = lpeg.P;
@@ -97,11 +110,11 @@
 			end };
 		{ P"on "^0 * day_name /
 			function (day_name)
-				time = find_nearest_day_by_name(time, day_name);
+				time = find_next_day_by_name(time, day_name:match("%S+$"));
 			end };
 		{ P"in "^0 * month_name /
 			function (month_name)
-				time = find_nearest_month_by_name(time, month_name);
+				time = find_next_month_by_name(time, month_name:match("%S+$"));
 			end };
 		{ P"in "^0 * ( quantity * P" " * unit_of_time ) * (P"s"^-1) /
 			function (number_and_unit)

mercurial