str2dateOfCurrentYear function

DateTime str2dateOfCurrentYear (
  1. String dateStr,
  2. {DateTime useCurrentTime}
)

Implementation

DateTime str2dateOfCurrentYear(String dateStr, {DateTime useCurrentTime}) {
  DateTime currentTime = new DateTime.now();
  if (!isValidMonthDateFormat(dateStr)) {
    return currentTime;
  }
  if (useCurrentTime != null) {
    currentTime = useCurrentTime;
  }
  int currentYear = currentTime.year;
  int targetMonth = int.parse(dateStr.split('/')[0]);
  int targetDay = int.parse(dateStr.split('/')[1]);
  DateTime targetTime = new DateTime.utc(currentYear, targetMonth, targetDay);
  return targetTime;
}