@@ -53,20 +53,21 @@ const Date Date::date()
5353{
5454#ifndef _WIN32
5555 struct timeval tv;
56- gettimeofday (&tv, NULL );
56+ gettimeofday (&tv, nullptr );
5757 int64_t seconds = tv.tv_sec ;
5858 return Date (seconds * MICRO_SECONDS_PER_SEC + tv.tv_usec );
5959#else
6060 timeval tv;
61- gettimeofday (&tv, NULL );
61+ gettimeofday (&tv, nullptr );
6262 int64_t seconds = tv.tv_sec ;
6363 return Date (seconds * MICRO_SECONDS_PER_SEC + tv.tv_usec );
6464#endif
6565}
6666const Date Date::after (double second) const
6767{
68- return Date (static_cast <int64_t >(microSecondsSinceEpoch_ +
69- second * MICRO_SECONDS_PER_SEC));
68+ return Date (microSecondsSinceEpoch_ +
69+ static_cast <int64_t >(
70+ second * static_cast <double >(MICRO_SECONDS_PER_SEC)));
7071}
7172const Date Date::roundSecond () const
7273{
@@ -86,7 +87,7 @@ const Date Date::roundDay() const
8687 t.tm_hour = 0 ;
8788 t.tm_min = 0 ;
8889 t.tm_sec = 0 ;
89- return Date (mktime (&t) * MICRO_SECONDS_PER_SEC);
90+ return Date (static_cast < int64_t >( mktime (&t) ) * MICRO_SECONDS_PER_SEC);
9091}
9192struct tm Date::tmStruct () const
9293{
@@ -281,8 +282,8 @@ std::string Date::toDbString() const
281282
282283Date Date::fromDbStringLocal (const std::string &datetime)
283284{
284- unsigned int year = { 0 } , month = { 0 } , day = { 0 } , hour = { 0 } , minute = { 0 } ,
285- second = { 0 } , microSecond = { 0 } ;
285+ unsigned int year = 0U , month = 0U , day = 0U , hour = 0U , minute = 0U ,
286+ second = 0U , microSecond = 0U ;
286287 std::vector<std::string> &&v = splitString (datetime, " " );
287288
288289 if (v.size () == 0 )
@@ -315,16 +316,16 @@ Date Date::fromDbStringLocal(const std::string &datetime)
315316 // Format YYYY-MM-DD HH:MM:SS[.UUUUUU] is given
316317 try
317318 {
318- year = std::stol (date[0 ]);
319- month = std::stol (date[1 ]);
320- day = std::stol (date[2 ]);
319+ year = static_cast < unsigned int >( std::stoul (date[0 ]) );
320+ month = static_cast < unsigned int >( std::stoul (date[1 ]) );
321+ day = static_cast < unsigned int >( std::stoul (date[2 ]) );
321322 std::vector<std::string> time = splitString (v[1 ], " :" );
322323 if (2 < time.size ())
323324 {
324- hour = std::stol (time[0 ]);
325- minute = std::stol (time[1 ]);
325+ hour = static_cast < unsigned int >( std::stoul (time[0 ]) );
326+ minute = static_cast < unsigned int >( std::stoul (time[1 ]) );
326327 auto seconds = splitString (time[2 ], " ." );
327- second = std::stol (seconds[0 ]);
328+ second = static_cast < unsigned int >( std::stoul (seconds[0 ]) );
328329 if (1 < seconds.size ())
329330 {
330331 if (seconds[1 ].length () > 6 )
@@ -335,7 +336,8 @@ Date Date::fromDbStringLocal(const std::string &datetime)
335336 {
336337 seconds[1 ].append (6 - seconds[1 ].length (), ' 0' );
337338 }
338- microSecond = std::stol (seconds[1 ]);
339+ microSecond =
340+ static_cast <unsigned int >(std::stoul (seconds[1 ]));
339341 }
340342 }
341343 }
@@ -358,7 +360,7 @@ Date Date::fromDbString(const std::string &datetime)
358360std::string Date::toCustomFormattedStringLocal (const std::string &fmtStr,
359361 bool showMicroseconds) const
360362{
361- char buf[256 ] = { 0 };
363+ char buf[256 ]{ };
362364 time_t seconds =
363365 static_cast <time_t >(microSecondsSinceEpoch_ / MICRO_SECONDS_PER_SEC);
364366 struct tm tm_time;
@@ -370,7 +372,7 @@ std::string Date::toCustomFormattedStringLocal(const std::string &fmtStr,
370372 strftime (buf, sizeof (buf), fmtStr.c_str (), &tm_time);
371373 if (!showMicroseconds)
372374 return std::string (buf);
373- char decimals[12 ] = { 0 };
375+ char decimals[12 ]{ };
374376 int microseconds =
375377 static_cast <int >(microSecondsSinceEpoch_ % MICRO_SECONDS_PER_SEC);
376378 snprintf (decimals, sizeof (decimals), " .%06d" , microseconds);
@@ -388,12 +390,12 @@ Date::Date(unsigned int year,
388390 memset (&tm, 0 , sizeof (tm));
389391 tm.tm_isdst = -1 ;
390392 time_t epoch;
391- tm.tm_year = year - 1900 ;
392- tm.tm_mon = month - 1 ;
393- tm.tm_mday = day;
394- tm.tm_hour = hour;
395- tm.tm_min = minute;
396- tm.tm_sec = second;
393+ tm.tm_year = static_cast < int >( year - 1900 ) ;
394+ tm.tm_mon = static_cast < int >( month - 1 ) ;
395+ tm.tm_mday = static_cast < int >( day) ;
396+ tm.tm_hour = static_cast < int >( hour) ;
397+ tm.tm_min = static_cast < int >( minute) ;
398+ tm.tm_sec = static_cast < int >( second) ;
397399 epoch = mktime (&tm);
398400 microSecondsSinceEpoch_ =
399401 static_cast <int64_t >(epoch) * MICRO_SECONDS_PER_SEC + microSecond;
0 commit comments