Skip to content

Commit 085551d

Browse files
committed
Simplify function
- Extract configuration of tm struct - Remove empty if-blocks
1 parent 3a52b07 commit 085551d

1 file changed

Lines changed: 7 additions & 30 deletions

File tree

src/Datetime.cpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,28 +1461,13 @@ bool Datetime::initializeOrdinal (Pig& pig)
14611461
int m = t->tm_mon + 1;
14621462
int d = t->tm_mday;
14631463

1464-
// If it is this month.
1465-
if (timeRelative && (d < number && number <= daysInMonth (y, m)))
1466-
{
1467-
t->tm_hour = t->tm_min = t->tm_sec = 0;
1468-
t->tm_mon = m - 1;
1469-
t->tm_mday = number;
1470-
t->tm_year = y - 1900;
1471-
t->tm_isdst = -1;
1472-
}
1473-
else if (timeRelative && (1 <= number && number <= d))
1464+
if (timeRelative && (1 <= number && number <= d))
14741465
{
14751466
if (++m > 12)
14761467
{
14771468
m = 1;
14781469
y++;
14791470
}
1480-
1481-
t->tm_hour = t->tm_min = t->tm_sec = 0;
1482-
t->tm_mon = m - 1;
1483-
t->tm_mday = number;
1484-
t->tm_year = y - 1900;
1485-
t->tm_isdst = -1;
14861471
}
14871472
else if (!timeRelative && (d < number && number <= daysInMonth (y, m)))
14881473
{
@@ -1491,22 +1476,14 @@ bool Datetime::initializeOrdinal (Pig& pig)
14911476
m = 12;
14921477
y--;
14931478
}
1494-
1495-
t->tm_hour = t->tm_min = t->tm_sec = 0;
1496-
t->tm_mon = m - 1;
1497-
t->tm_mday = number;
1498-
t->tm_year = y - 1900;
1499-
t->tm_isdst = -1;
1500-
}
1501-
else if (!timeRelative && (1 <= number && number <= d))
1502-
{
1503-
t->tm_hour = t->tm_min = t->tm_sec = 0;
1504-
t->tm_mon = m - 1;
1505-
t->tm_mday = number;
1506-
t->tm_year = y - 1900;
1507-
t->tm_isdst = -1;
15081479
}
15091480

1481+
t->tm_hour = t->tm_min = t->tm_sec = 0;
1482+
t->tm_mon = m - 1;
1483+
t->tm_mday = number;
1484+
t->tm_year = y - 1900;
1485+
t->tm_isdst = -1;
1486+
15101487
_date = mktime (t);
15111488

15121489
return true;

0 commit comments

Comments
 (0)