Al-Nawawi (may Allah have mercy on him) said in al-Majmoo’ (2/386):
The ummah is unanimously agreed that it is haraam for women who are menstruating or bleeding following childbirth to fast and that their fast is not valid… The ummah is also unanimously agreed that it is obligatory for these women to make up missed Ramadan fasts. Al-Tirmidhi, Ibn al-Mundhir, Ibn Jareer, our companions and others narrated that there was consensus on this point.
Ibn Qudaamah said in al-Mughni (4/397):
The scholars are unanimously agreed that it is not permissible for women who are menstruating or bleeding following childbirth to fast, and that they should not fast in Ramadan but should make up missed fasts. If they do fast, their fast is not accepted. ‘Aa’ishah said: “We used to menstruate at the time of the Messenger of Allah (peace and blessings of Allah be upon him), and we were commanded to make up the fasts, but we were not commanded to make up the prayers.” Agreed upon. The one who commanded them thus was the Prophet (peace and blessings of Allah be upon him). Abu Sa’eed said: The Prophet (peace and blessings of Allah be upon him) said: “Is it not the case that when one of you menstruates, she does not pray or fast? That is what is meant by lacking in religious commitment.” Narrated by al-Bukhaari.
Menstruating women and women who are bleeding following childbirth are regarded as the same, because the blood of nifaas is like the blood of menstruation, so it comes under the same rulings. If menstruation starts during the day, the fast of that day is invalidated, whether it starts at the beginning of the day or at the end. If a menstruating woman intends to fast and refrains from eating or drinking, even though she knows that that is haraam, she is committing a sin, and that fast does not count.
Shaykh Ibn ‘Uthaymeen said in his essay al-Dima’ al-Tabee’iyyah li’l-Nisa’ (p.28):
If a woman menstruates when she is fasting, her fast is invalidated even if that is a moment just before sunset, and she has to make up that day if it was an obligatory fast.
If she feels that her period is about to begin but nothing comes out until after sunset, then her fast is complete and is not invalidated, according to the correct view.
The Standing Committee (10/155) was asked about a woman who fasted and shortly before sunset and before the adhaan, her period came. Is her fast valid?
They replied: If her period came before sunset her fast is invalid and she has to make it up. If it came after sunset then her fast is valid and she does not have to make it up.