Permalink
Browse files

Simplify function

- Extract configuration of tm struct
- Remove empty if-blocks
  • Loading branch information...
lauft committed Nov 2, 2018
1 parent 3a52b07 commit 085551dc480ebfc6f4accaf0a7eaffe5c57fba2d
Showing with 7 additions and 30 deletions.
  1. +7 −30 src/Datetime.cpp
@@ -1461,28 +1461,13 @@ bool Datetime::initializeOrdinal (Pig& pig)
int m = t->tm_mon + 1;
int d = t->tm_mday;

// If it is this month.
if (timeRelative && (d < number && number <= daysInMonth (y, m)))
{
t->tm_hour = t->tm_min = t->tm_sec = 0;
t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
t->tm_isdst = -1;
}
else if (timeRelative && (1 <= number && number <= d))
if (timeRelative && (1 <= number && number <= d))
{
if (++m > 12)
{
m = 1;
y++;
}

t->tm_hour = t->tm_min = t->tm_sec = 0;
t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
t->tm_isdst = -1;
}
else if (!timeRelative && (d < number && number <= daysInMonth (y, m)))
{
@@ -1491,22 +1476,14 @@ bool Datetime::initializeOrdinal (Pig& pig)
m = 12;
y--;
}

t->tm_hour = t->tm_min = t->tm_sec = 0;
t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
t->tm_isdst = -1;
}
else if (!timeRelative && (1 <= number && number <= d))
{
t->tm_hour = t->tm_min = t->tm_sec = 0;
t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
t->tm_isdst = -1;
}

t->tm_hour = t->tm_min = t->tm_sec = 0;
t->tm_mon = m - 1;
t->tm_mday = number;
t->tm_year = y - 1900;
t->tm_isdst = -1;

_date = mktime (t);

return true;

0 comments on commit 085551d

Please sign in to comment.