tasks r426 - in trunk: . libkoto
- From: rburton svn gnome org
- To: svn-commits-list gnome org
- Subject: tasks r426 - in trunk: . libkoto
- Date: Thu, 23 Oct 2008 18:53:40 +0000 (UTC)
Author: rburton
Date: Thu Oct 23 18:53:39 2008
New Revision: 426
URL: http://svn.gnome.org/viewvc/tasks?rev=426&view=rev
Log:
2008-10-23 Ross Burton <ross linux intel com>
* libkoto/koto-date-parser.c:
Add "foo in 5 days" and "in 5 weeks" patterns.
Modified:
trunk/ChangeLog
trunk/libkoto/koto-date-parser.c
Modified: trunk/libkoto/koto-date-parser.c
==============================================================================
--- trunk/libkoto/koto-date-parser.c (original)
+++ trunk/libkoto/koto-date-parser.c Thu Oct 23 18:53:39 2008
@@ -379,6 +379,47 @@
return date;
}
+static GDate *
+match_days (const char *input, GMatchInfo *info)
+{
+ GDate *date;
+ char *days_s;
+ int days;
+
+ days_s = g_match_info_fetch_named (info, "days");
+ if (!days_s)
+ return NULL;
+ days = atoi (days_s);
+ g_free (days_s);
+
+ if (days < 1)
+ return NULL;
+
+ date = today ();
+ g_date_add_days (date, days);
+ return date;
+}
+
+static GDate *
+match_weeks (const char *input, GMatchInfo *info)
+{
+ GDate *date;
+ char *weeks_s;
+ int weeks;
+
+ weeks_s = g_match_info_fetch_named (info, "weeks");
+ if (!weeks_s)
+ return NULL;
+ weeks = atoi (weeks_s);
+ g_free (weeks_s);
+
+ if (weeks < 1)
+ return NULL;
+
+ date = today ();
+ g_date_add_days (date, weeks * 7);
+ return date;
+}
static Matcher*
matcher_new (const gchar *regex_str, MatchFunc func)
@@ -478,6 +519,18 @@
English, w34 means "week 34". */
m = matcher_new (_("^(?<task>.+) (?:by|due|on)? w(?<week>\\d{1,2})$"), match_week);
if (m) matchers = g_list_prepend (matchers, m);
+
+ /* Translators: just translate in ... days to contain relevant words in your
+ language. Remember the trailing ? is part of the regular expression to be
+ translated.*/
+ m = matcher_new (_("^(?<task>.+) in (?<days>\\d+) days?$"), match_days);
+ if (m) matchers = g_list_prepend (matchers, m);
+
+ /* Translators: just translate in ... weeksto contain relevant words in your
+ language. Remember the trailing ? is part of the regular expression to be
+ translated.*/
+ m = matcher_new (_("^(?<task>.+) in (?<weeks>\\d+) weeks?$"), match_weeks);
+ if (m) matchers = g_list_prepend (matchers, m);
return g_list_reverse (matchers);
}
@@ -696,6 +749,14 @@
TEST_PARSER ("foo on 4-13-08", "foo");
g_date_set_dmy (expected, 1, 1, 2008);
TEST_PARSER ("foo on 1-1-8", "foo");
+ /* All out of range */
+ TEST_PARSER_FAIL ("foo on 99/99/99");
+ /* Invalid month */
+ TEST_PARSER_FAIL ("foo on 13/1/08");
+ /* Invalid day */
+ TEST_PARSER_FAIL ("foo on 1/32/07");
+ TEST_PARSER_FAIL ("foo on 2/29/07");
+ TEST_PARSER_FAIL ("foo on 4/31/07");
/* Week numbers */
@@ -717,14 +778,36 @@
g_date_set_dmy (expected, 9, 3, 2009);
TEST_PARSER ("foo on w11", "foo");
- /* All out of range */
- TEST_PARSER_FAIL ("foo on 99/99/99");
- /* Invalid month */
- TEST_PARSER_FAIL ("foo on 13/1/08");
- /* Invalid day */
- TEST_PARSER_FAIL ("foo on 1/32/07");
- TEST_PARSER_FAIL ("foo on 2/29/07");
- TEST_PARSER_FAIL ("foo on 4/31/07");
+ /* In x days */
+
+ g_date_set_dmy (expected, 12, 3, 2008);
+ TEST_PARSER ("foo in 1 day", "foo");
+
+ g_date_set_dmy (expected, 13, 3, 2008);
+ TEST_PARSER ("foo in 2 days", "foo");
+
+ g_date_set_dmy (expected, 10, 4, 2008);
+ TEST_PARSER ("foo in 30 days", "foo");
+
+ g_date_set_dmy (expected, 11, 3, 2009);
+ TEST_PARSER ("foo in 365 days", "foo");
+
+ TEST_PARSER_FAIL ("foo in -10 days");
+ TEST_PARSER_FAIL ("foo in 0 days");
+
+ /* In x weeks */
+
+ g_date_set_dmy (expected, 18, 3, 2008);
+ TEST_PARSER ("foo in 1 week", "foo");
+
+ g_date_set_dmy (expected, 25, 3, 2008);
+ TEST_PARSER ("foo in 2 weeks", "foo");
+
+ g_date_set_dmy (expected, 20, 5, 2008);
+ TEST_PARSER ("foo in 10 weeks", "foo");
+
+ TEST_PARSER_FAIL ("foo in -10 weeks");
+ TEST_PARSER_FAIL ("foo in 0 weeks");
g_date_free (expected);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]