He further wrote in section 10: If one was eating and Shabbat departed—he mentions Shabbat in Birkat HaMazon, for we follow the beginning of the meal. And the same applies to Rosh Chodesh, Purim, and Chanukah. Thus far his words. And the commentators of the Shulchan Aruch elaborated on this. For the halacha, the primary view is like the words of our teacher, the Beit Yosef, that we only follow the beginning of the meal. Therefore, if Rosh Chodesh falls on Saturday night—he should not mention Rosh Chodesh. However, if he prayed Maariv before Birkat HaMazon, it is impossible to mention Shabbat: since he already made it a weekday through prayer, how can he mention Shabbat? It would be a contradiction. And so too regarding Rosh Chodesh, Chanukah, and Purim. Similarly, if he performed Havdalah, or said "Who separates between the holy and the profane"—he should not mention Shabbat. And so too the reverse: if he ate during the day and it extended into the night, and at night it was Rosh Chodesh, and before Birkat HaMazon he prayed Maariv—perforce he must mention "Ya'aleh V'Yavo" in Birkat HaMazon, since he already made it Rosh Chodesh through prayer. And this is not because we follow the end of the meal, but because perforce he made this mention an obligation upon himself. And so too in all similar cases. And there is no difference whether he ate bread at night or did not eat, for the primary factor is the beginning of the meal. (The Taz and the Eliyah Rabbah are of the opinion to also follow the end of the meal, but such is not the opinion of the Bach and the Magen Avraham. And the Magen Avraham's opinion is that if he ate bread at night—he should mention the night, see there. And it is explicitly proven that it is not so. Now, all that they were pressed with in this matter is because of the Baraita in Pesachim 102a where they were reclining and the day became sanctified upon them, where Rabbi Yosei holds the first says Birkat HaMazon over it, and the second Kiddush of the day. And it is taught in the Tosefta that he mentions Shabbat in Birkat HaMazon, as the Rosh wrote in Responsa, siman 22. In my humble opinion, it is not difficult at all, for there, since according to the fundamental law he would have needed to also say Kiddush of the day over this cup, as the Gemara asks in Pesachim ibid. regarding Rabbi Yosei: "And let us say both of them on one cup," and answers that we do not perform commandments in bundles, see there. However, the obligation is incumbent upon him in any event to sanctify immediately, and it is as if the Kiddush is prepared and standing, so how could he not mention Shabbat? But in all other meals, we have only the beginning alone. And so is the primary halacha.)
עוד כתב בסעיף י: היה אוכל, ויצא שבת – מזכיר של שבת בברכת המזון, דאזלינן בתר התחלת הסעודה. והוא הדין לראש חודש ופורים וחנוכה. עד כאן לשונו. ומפרשי השולחן ערוך האריכו בזה. ולדינא העיקר כדברי רבינו הבית יוסף, דאזלינן רק אחר התחלת הסעודה. ולכן אם חל ראש חודש במוצאי שבת – לא יזכיר של ראש חודש. אמנם אם התפלל ערבית קודם ברכת המזון אי אפשר להזכיר של שבת: כיון שעשאו כבר חול בתפילה, איך יזכיר של שבת והוי תרתי דסתרי? וכן בראש חודש וחנוכה ופורים. וכן אם הבדיל, או שאמר "המבדיל בין קודש לחול" – לא יזכיר של שבת. וכן להיפך: אם אכל ביום ונמשך עד הלילה, ובלילה היה ראש חודש, וקודם ברכת המזון התפלל מעריב – בעל כרחך שצריך להזכיר "יעלה ויבוא" בברכת המזון, כיון שכבר עשאו ראש חודש בתפילה. ולאו משום דאזלינן בתר גמר סעודה, אלא משום דבעל כרחך עשאה הזכרה זו לחיוב עליו. וכן כל כיוצא בזה. ואין חילוק בין אכל פת בלילה או לא אכל, דהעיקר הוא התחלת הסעודה. (הט"ז והאליה רבה דעתם לילך גם אחר גמר הסעודה, ואין כן דעת הב"ח והמגן אברהם. והמגן אברהם דעתו דאם אכל פת בלילה – יש להזכיר של לילה, עיין שם. ולהדיא מוכח דאינו כן. והנה כל מה שנדחקו בזה הוא מפני הברייתא דפסחים קב א דהיו מסובין וקידש עליהם היום, דסבירא ליה לרבי יוסי ראשון אומר עליו ברכת המזון, ושני קדושת היום. ותניא בתוספתא דמזכיר בברכת המזון של שבת, כמו שכתב הרא"ש בתשובה סימן כ"ב. לעניות דעתי לא קשיא כלל, דהתם כיון דמעיקר הדין היה צריך לומר על כוס זה גם קדושת היום, כדפריך הש"ס בפסחים שם לרבי יוסי: "ונמרינהו תרוויהו אחד כסא", ומתרץ שאין עושין חבילות, עיין שם. מיהו החיוב מוטל עליו על כל פנים לקדש מיד, והוה כאילו הקידוש מוכן ועומד, ואיך לא יזכיר של שבת? אבל בכל הסעודות אין לנו רק ההתחלה בלבד. וכן עיקר לדינא.)