Ruling 723:
For a person under normal circumstances, the time for the maghrib prayer is until midnight, but for a helpless person – who due to forgetfulness, oversleeping, menstruation (ḥayḍ), or suchlike did not perform prayers before midnight – the time for maghrib and ʿishāʾ prayers is extended until dawn. However, in both cases, the proper order between the two prayers must be observed, meaning that if the ʿishāʾ prayer is knowingly performed before the maghrib prayer, it is invalid unless the time remaining is sufficient only for performing the ʿishāʾ prayer, in which case it is necessary that one performs the ʿishāʾ prayer before the maghrib prayer.
'Midnight' in the above law is the legal midnight and not 12:00 which is calculate the total hours between sunset to sunrise of the next day and divide by 2