@@ -633,14 +633,17 @@ inline bool CastToDatetimeV2::from_string_strict_mode(const StringRef& str,
633633 " invalid timezone name '{}'" , std::string {start, ptr});
634634 }
635635 // convert tz
636- cctz::civil_second cs {res.year (), res.month (), res.day (),
637- res.hour (), res.minute (), res.second ()};
638-
639636 if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
640637 // if not timestamptz, the given time is in local_time_zone
641638 SET_PARAMS_RET_FALSE_IFN (
642639 local_time_zone != nullptr ,
643- " local time zone required for datetime string without timezone" );
640+ " local time zone required for datetime string with timezone" );
641+ }
642+
643+ cctz::civil_second cs {res.year (), res.month (), res.day (),
644+ res.hour (), res.minute (), res.second ()};
645+
646+ if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
644647 auto given = cctz::convert (cs, parsed_tz);
645648 auto local = cctz::convert (given, *local_time_zone);
646649 res.unchecked_set_time_unit <TimeUnit::YEAR>((uint32_t )local.year ());
@@ -913,14 +916,17 @@ inline bool CastToDatetimeV2::from_string_non_strict_mode_impl(
913916 }
914917
915918 // convert tz
916- cctz::civil_second cs {res.year (), res.month (), res.day (),
917- res.hour (), res.minute (), res.second ()};
918-
919919 if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
920920 // if not timestamptz, the given time is in local_time_zone
921921 SET_PARAMS_RET_FALSE_IFN (
922922 local_time_zone != nullptr ,
923- " local time zone required for datetime string without timezone" );
923+ " local time zone required for datetime string with timezone" );
924+ }
925+
926+ cctz::civil_second cs {res.year (), res.month (), res.day (),
927+ res.hour (), res.minute (), res.second ()};
928+
929+ if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
924930 auto given = cctz::convert (cs, parsed_tz);
925931 auto local = cctz::convert (given, *local_time_zone);
926932 res.unchecked_set_time_unit <TimeUnit::YEAR>((uint32_t )local.year ());
0 commit comments