}
}
+static const char* mstr_a[] = {
+ "Jan", "Feb", "Mar", "Apr",
+ "May", "Jun", "Jul", "Aug",
+ "Sep", "Oct", "Nov", "Dec"
+};
+static const char* mstr[] = {
+ "January", "February", "March", "April",
+ "May", "June", "July", "August",
+ "September", "October", "November", "December"
+};
static void format_month (ustring& ans, MNode* a, std::vector<ustring>& par) {
- static const char* mstr_a[] = {
- "Jan", "Feb", "Mar", "Apr",
- "May", "Jun", "Jul", "Aug",
- "Sep", "Oct", "Nov", "Dec"
- };
format_literal (ans, a, mstr_a, 1, 12);
}
static void format_Month (ustring& ans, MNode* a, std::vector<ustring>& par) {
- static const char* mstr[] = {
- "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December"
- };
format_literal (ans, a, mstr, 1, 12);
}
/*
${Y:4}, ${Y:2}
- ${M:2}, ${M}
+ ${M:2}, ${M}, ${M:name}, ${M:ab}
${D:2}, ${D}
${h:2}, ${h}
${m:2}, ${m}
${s:2}, ${s}
${W}, ${w}
+ ${o}
*/
ustring formatDateString (const ustring& format, time_t tm) {
ustring ans;
uiterator b, e;
umatch m;
int pc;
- static uregex re ("\\$\\{([YMDhmsWw])(:([0-9]))?\\}");
+// static uregex re ("\\$\\{([YMDhmsWw])(:([0-9]))?\\}");
+ static uregex re ("\\$\\{(([YMDhmsWwo])(:([0-9]))?|M:((name)|(ab)|(abname)))\\}");
std::vector<ustring> fpar;
localtime_r (&tm, &v);
while (usearch (b, e, m, re)) {
ans.append (b, m[0].first);
b = m[0].second;
- if (m[2].matched) {
- pc = strtol (ustring (m[3].first, m[3].second));
+ if (m[5].matched) {
+ if (m[6].matched) { // name
+ ans.append (mstr[v.tm_mon]);
+ } else if (m[7].matched || m[8].matched) { // abname
+ ans.append (mstr_a[v.tm_mon]);
+ }
} else {
- pc = 0;
- }
- switch (*m[1].first) {
- case 'Y':
- ans.append (colpad0 (pc, to_ustring (v.tm_year + 1900)));
- break;
- case 'M':
- ans.append (colpad0 (pc, to_ustring (v.tm_mon + 1)));
- break;
- case 'D':
- ans.append (colpad0 (pc, to_ustring (v.tm_mday)));
- break;
- case 'h':
- ans.append (colpad0 (pc, to_ustring (v.tm_hour)));
- break;
- case 'm':
- ans.append (colpad0 (pc, to_ustring (v.tm_min)));
- break;
- case 's':
- ans.append (colpad0 (pc, to_ustring (v.tm_sec)));
- break;
- case 'W':
- ans.append (WStr [v.tm_wday]);
- break;
- case 'w':
- ans.append (WStr_a [v.tm_wday]);
- break;
+// if (m[2].matched) {
+ if (m[3].matched) {
+// pc = strtol (ustring (m[3].first, m[3].second));
+ pc = strtol (ustring (m[4].first, m[4].second));
+ } else {
+ pc = 0;
+ }
+// switch (*m[1].first) {
+ switch (*m[2].first) {
+ case 'Y':
+ ans.append (colpad0 (pc, to_ustring (v.tm_year + 1900)));
+ break;
+ case 'M':
+ ans.append (colpad0 (pc, to_ustring (v.tm_mon + 1)));
+ break;
+ case 'D':
+ ans.append (colpad0 (pc, to_ustring (v.tm_mday)));
+ break;
+ case 'h':
+ ans.append (colpad0 (pc, to_ustring (v.tm_hour)));
+ break;
+ case 'm':
+ ans.append (colpad0 (pc, to_ustring (v.tm_min)));
+ break;
+ case 's':
+ ans.append (colpad0 (pc, to_ustring (v.tm_sec)));
+ break;
+ case 'W':
+ ans.append (WStr [v.tm_wday]);
+ break;
+ case 'w':
+ ans.append (WStr_a [v.tm_wday]);
+ break;
+ case 'o':
+ {
+ int h, m;
+ if (v.tm_gmtoff < 0) {
+ h = - v.tm_gmtoff / 60;
+ m = h % 60;
+ h = h / 60;
+ ans.append (CharConst ("-")).append (colpad0 (4, to_ustring (h * 100 + m)));
+ } else {
+ h = v.tm_gmtoff / 60;
+ m = h % 60;
+ h = h / 60;
+ ans.append (CharConst ("+")).append (colpad0 (4, to_ustring (h * 100 + m)));
+ }
+ }
+ break;
+ }
}
}
ans.append (b, e);