Setting the Day Period on TimeOfDay

695 Views Asked by At

Im trying to set the TimeOfDay behind the scenes without input from the time picker. The time is set correctly, but the Day Period is incorrect. I'm assuming it grabs this data from the time picker, but since we are bypassing it, it defaults to the incorrect day period. There is a period property, but it looks like it is just a getter. Is there a way to manually set the Day Period on a TimeOfDay object?

if (!selectTimeOfDay) {
  final TimeOfDay allDayTime;

  if (placeholder == 'Start Date') {
    allDayTime = TimeOfDay(hour: 12, minute: 0);  //set period to AM here        
  } else {
    allDayTime = TimeOfDay(hour: 11, minute: 59); // set period to PM here
  }

  onChanged(DateTime(date.year, date.month, date.day, allDayTime.hour, allDayTime.minute));

  return;
}

The period is displayed, just in reverse. It should say 12:00AM - 11:59PM, but it says 12:00PM - 11:59AM.

1

There are 1 best solutions below

0
On

Silly mistake on my end. I needed to format the hours in 0 - 24.

    if (!selectTimeOfDay) {
  final TimeOfDay allDayTime;

  if (placeholder == 'Start Date') {
    allDayTime = TimeOfDay(hour: 0, minute: 0);  //set period to AM here        
  } else {
    allDayTime = TimeOfDay(hour: 23, minute: 59); // set period to PM here
  }

  onChanged(DateTime(date.year, date.month, date.day, allDayTime.hour, allDayTime.minute));

  return;
}