| 447 | |
| 448 | |
| 449 | def get_datetime_from_seconds(seconds_after_midnight, date_str): |
| 450 | # Convert the date_str to a datetime.date object. |
| 451 | dt_date = datetime.strptime(date_str, "%Y-%m-%d").date() |
| 452 | |
| 453 | # Calculate the time component from seconds_after_midnight. |
| 454 | hours = int(seconds_after_midnight // 3600) |
| 455 | minutes = int((seconds_after_midnight % 3600) // 60) |
| 456 | seconds = int(seconds_after_midnight % 60) |
| 457 | microseconds = int( |
| 458 | (seconds_after_midnight % 1) * 1e6 |
| 459 | ) # Convert decimal part to microseconds. |
| 460 | |
| 461 | # Create a datetime.time object for the time component. |
| 462 | dt_time = time(hour=hours, minute=minutes, second=seconds, microsecond=microseconds) |
| 463 | |
| 464 | # Combine the date and time to create the datetime.datetime object. |
| 465 | dt_datetime = datetime.combine(dt_date, dt_time) |
| 466 | |
| 467 | return dt_datetime |