1
1
mirror of https://github.com/tstack/lnav.git synced 2024-09-19 08:48:02 +03:00

[ptime] fix am/pm issue again

Fixes #520
This commit is contained in:
Timothy Stack 2018-05-23 08:31:05 -07:00
parent 5e0dabb231
commit 9e1411f113
4 changed files with 14 additions and 9 deletions

View File

@ -451,11 +451,11 @@ inline void ftime_I(char *dst, off_t &off_inout, ssize_t len, const struct exttm
{
int hour = tm.et_tm.tm_hour;
if (hour > 12) {
if (hour >= 12) {
hour -= 12;
if (hour == 0) {
hour = 12;
}
}
if (hour == 0) {
hour = 12;
}
PTIME_APPEND('0' + ((hour / 10) % 10));
@ -623,11 +623,11 @@ inline void ftime_l(char *dst, off_t &off_inout, ssize_t len, const struct exttm
{
int hour = tm.et_tm.tm_hour;
if (hour > 12) {
if (hour >= 12) {
hour -= 12;
if (hour == 0) {
hour = 12;
}
}
if (hour == 0) {
hour = 12;
}
if (hour < 10) {
@ -648,6 +648,9 @@ inline bool ptime_p(struct exttm *dst, const char *str, off_t &off_inout, ssize_
return false;
}
else if ((lead & 0xdf) == 'A') {
if (dst->et_tm.tm_hour == 12) {
dst->et_tm.tm_hour -= 12;
}
}
else if ((lead & 0xdf) == 'P') {
if (dst->et_tm.tm_hour > 12) {

View File

@ -182,7 +182,7 @@ bool relative_time::parse(const char *str, size_t len, struct parse_error &pe_ou
this->rt_field[RTF_HOURS] = 0;
}
}
else {
else if (this->rt_field[RTF_HOURS] < 12) {
this->rt_field[RTF_HOURS] += 12;
}
break;

View File

@ -41,6 +41,7 @@ static const char *GOOD_TIMES[] = {
"May 10 12:00:01",
"2014-02-11 16:12:34",
"05/18/2018 12:00:53 PM",
"05/18/2018 12:00:53 AM",
NULL
};

View File

@ -52,6 +52,7 @@ static struct {
{ "01:40", "0y0m0d1H40M0S0U" },
{ "1h40m", "0y0m0d1h40m0s0u" },
{ "1pm", "0y0m0d13H0M0S0U" },
{ "12pm", "0y0m0d12H0M0S0U" },
{ "00:27:18.567", "0y0m0d0H27M18S567000U" },
{ NULL, NULL }