summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-03 14:39:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-07-03 14:42:48 +0300
commitdc2d8bacb8b5c4874b884771fb4f3e5d74e960c9 (patch)
treedfcd66a4c75c6c51cb0d0bbae9a36219412dd046
parent0d0ad2f817ca89ad9135ab0497780c08d7671530 (diff)
downloadmailutils-dc2d8bacb8b5c4874b884771fb4f3e5d74e960c9.tar.gz
mailutils-dc2d8bacb8b5c4874b884771fb4f3e5d74e960c9.tar.bz2
Test mh format date functions
* mh/mh_format.c (builtin_sday, builtin_szone): Mark as not implemented (builtin_zone): Fix output (builtin_tzone): Fix output * mh/tests/fmtfunc.at: Test most date functions.
-rw-r--r--mh/mh_format.c101
-rw-r--r--mh/tests/fmtfunc.at149
2 files changed, 187 insertions, 63 deletions
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 0f1d4b728..abbdc783a 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -913,3 +913,3 @@ builtin_trim (struct mh_fvm *mach)
-static int
+static void
_parse_date (struct mh_fvm *mach, struct tm *tm, struct mu_timezone *tz)
@@ -928,4 +928,2 @@ _parse_date (struct mh_fvm *mach, struct tm *tm, struct mu_timezone *tz)
}
-
- return 0;
}
@@ -939,5 +937,3 @@ builtin_sec (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
-
+ _parse_date (mach, &tm, &tz);
mach->num[R_REG] = tm.tm_sec;
@@ -952,4 +948,3 @@ builtin_min (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -965,4 +960,3 @@ builtin_hour (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -978,4 +972,3 @@ builtin_wday (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -992,4 +985,3 @@ builtin_day (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1007,4 +999,4 @@ builtin_weekday (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
+
strftime (buf, sizeof buf, "%A", &tm);
@@ -1014,3 +1006,3 @@ builtin_weekday (struct mh_fvm *mach)
/* sday date integer day of the week known?
- (0=implicit,-1=unknown) */
+ (1=explicit,0=implicit,-1=unknown) */
static void
@@ -1018,10 +1010,5 @@ builtin_sday (struct mh_fvm *mach)
{
- struct tm tm;
- struct mu_timezone tz;
-
- /*FIXME: more elaborate check needed */
- if (_parse_date (mach, &tm, &tz))
- mach->num[R_REG] = -1;
- else
- mach->num[R_REG] = 1;
+ /* FIXME */
+ return builtin_not_implemented ("sday");
+ mach->num[R_REG] = -1;
}
@@ -1035,4 +1022,3 @@ builtin_mday (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1048,4 +1034,3 @@ builtin_yday (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1061,4 +1046,3 @@ builtin_mon (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1075,4 +1059,3 @@ builtin_month (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1090,4 +1073,3 @@ builtin_lmonth (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1104,4 +1086,3 @@ builtin_year (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1110,3 +1091,4 @@ builtin_year (struct mh_fvm *mach)
-/* zone date integer timezone in hours*/
+/* zone date integer timezone in hours
+ FIXME: mh and nmh return the value as given, e.g. 0300 is returned as 300 */
static void
@@ -1117,6 +1099,5 @@ builtin_zone (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
- mach->num[R_REG] = tz.utc_offset;
+ mach->num[R_REG] = tz.utc_offset / 3600;
}
@@ -1130,4 +1111,3 @@ builtin_tzone (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
@@ -1139,2 +1119,4 @@ builtin_tzone (struct mh_fvm *mach)
int s;
+ unsigned hrs;
+
if (tz.utc_offset < 0)
@@ -1146,4 +1128,5 @@ builtin_tzone (struct mh_fvm *mach)
s = '+';
- snprintf (buf, sizeof buf, "%c%02d%02d", s,
- tz.utc_offset/3600, tz.utc_offset/60);
+ hrs = tz.utc_offset / 3600;
+ snprintf (buf, sizeof buf, "%c%02u%02u", s,
+ hrs, (tz.utc_offset - hrs * 3600) / 60);
mh_string_load (&mach->str[R_REG], buf);
@@ -1157,10 +1140,5 @@ builtin_szone (struct mh_fvm *mach)
{
- struct tm tm;
- struct mu_timezone tz;
-
- /*FIXME: more elaborate check needed */
- if (_parse_date (mach, &tm, &tz))
- mach->num[R_REG] = -1;
- else
- mach->num[R_REG] = 1;
+ /*FIXME:*/
+ builtin_not_implemented ("szone");
+ mach->num[R_REG] = -1;
}
@@ -1193,2 +1171,3 @@ builtin_dst (struct mh_fvm *mach)
{
+#ifdef HAVE_STRUCT_TM_TM_ISDST
struct tm tm;
@@ -1196,5 +1175,4 @@ builtin_dst (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
-#ifdef HAVE_STRUCT_TM_TM_ISDST
+ _parse_date (mach, &tm, &tz);
+
mach->num[R_REG] = tm.tm_isdst;
@@ -1212,4 +1190,4 @@ builtin_clock (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
+
mach->num[R_REG] = mu_datetime_to_utc (&tm, &tz);
@@ -1225,4 +1203,4 @@ builtin_rclock (struct mh_fvm *mach)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
+
mach->num[R_REG] = now - mu_datetime_to_utc (&tm, &tz);
@@ -1254,4 +1232,3 @@ date_cvt (struct mh_fvm *mach, int pretty)
- if (_parse_date (mach, &tm, &tz))
- return;
+ _parse_date (mach, &tm, &tz);
diff --git a/mh/tests/fmtfunc.at b/mh/tests/fmtfunc.at
index 2abda39b1..a1cf2ae60 100644
--- a/mh/tests/fmtfunc.at
+++ b/mh/tests/fmtfunc.at
@@ -114,3 +114,2 @@ FMTFUNC([charleft],
# FIXME: timenow
-# FIXME: ne
# FIXME: myhost
@@ -413,2 +412,150 @@ data
+FMTFUNC([sec],
+[%(sec{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[58
+])
+
+FMTFUNC([min],
+[%(min{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[17
+])
+
+FMTFUNC([hour],
+[%(hour{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[13
+])
+
+FMTFUNC([wday],
+[%(wday{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[1
+])
+
+FMTFUNC([day],
+[%(day{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[Mon
+])
+
+FMTFUNC([weekday],
+[%(weekday{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[Monday
+])
+
+# FIXME: sday
+
+FMTFUNC([mday],
+[%(mday{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[3
+])
+
+FMTFUNC([yday],
+[%(yday{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[183
+])
+
+FMTFUNC([mon],
+[%(mon{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[7
+])
+
+FMTFUNC([month],
+[%(month{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[Jul
+])
+
+FMTFUNC([lmonth],
+[%(lmonth{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[July
+])
+
+FMTFUNC([year],
+[%(year{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[2017
+])
+
+# FIXME: zone
+
+FMTFUNC([tzone],
+[%(tzone{Date})
+],
+[Date: Mon, 3 Jul 2017 13:17:58 +0300
+
+],
+[+0300
+])
+
+# FIXME: szone
+
+# FIXME: date2local
+
+# FIXME: date2gmt
+
+# FIXME: dst
+# FMTFUNC([dst],
+# [%(dst{Date})
+# %(dst{X-Date})
+# ],
+# [Date: Mon, 3 Jul 2017 13:17:58 +0300
+# X-Date: Sun, 1 Jan 2017 10:11:00 +0200
+
+# ],
+# [1
+# 0
+# ])
+
+# FIXME: clock
+
+# FIXME: rclock
+
+# FIXME: tws
+
+# FIXME: pretty
+
m4_popdef([FMTFUNC]) \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.