This is what our teacher, the Beit Yosef, wrote in section 1: An individual who accepted upon himself a fast of such and such days, and Sabbaths and Festivals occurred within them, or Rosh Chodesh, Chanukah and Purim, or the eve of Yom Kippur, if he accepted it with the language of a general acceptance of a fast – he does not require annulment. But if he accepted it with the language of "behold it is upon me," which is the language of a vow – he requires annulment by a sage. And he opens with regret, for he shall say to him: "If you had set to your heart that these days would occur within them, you would not have vowed," and he annuls it for him. And according to the Rambam, once he accepted it upon himself with the language of a vow, and Sabbaths and Festivals, or the eve of Yom Kippur, or Rosh Chodesh happened upon him – he is obligated to fast on them if they do not annul it for him. But if Chanukah and Purim happened upon him – his vow is void and he shall not fast on them, because they are from the words of the sages and require reinforcement. Thus far his words. The explanation of when he said "behold it is upon me" is: he must say "behold the eating of such a day is a konam upon me," or a vow or a prohibition. But if he said "behold it is upon me to fast" – it is not called a vow (Magen Avraham, subsection 2), for we require a prohibition on the object, and a fast is not an object. And it is like any acceptance of a fast.
וזהו שכתב רבינו הבית יוסף בסעיף א: יחיד שקבל עליו תענית כך וכך ימים, ואירעו בהם שבתות וימים טובים, או ראש חודש חנוכה ופורים, או ערב יום הכיפורים, אם קבלו בלשון קבלת תענית בעלמא – אינו צריך התרה. ואם קבלו בלשון "הרי עלי" שהוא לשון נדר – צריך התרת חכם. ויפתח בחרטה, שיאמר לו: "אילו שמת אל לבך שיארעו בהם אלו הימים לא היית נודר", ומתיר לו. ולהרמב"ם משקיבל עליו בלשון נדר, ופגעו בו שבתות וימים טובים, או ערב יום הכיפורים, או ראש חודש – חייב לצום בהם אם לא יתירו לו. אבל אם פגע בו חנוכה ופורים – נדרו בטל ולא יצום בהם, מפני שהם מדבריהם וצריכין חיזוק. עד כאן לשונו. פירוש כשאמר "הרי עלי": צריך שיאמר "הרי עלי אכילת יום פלוני קונם", או נדר או איסור. אבל אם אמר "הרי עלי להתענות" – לא מקרי נדר (מגן אברהם סעיף קטן ב), דבעינן איסור חפצא, ותענית אינו חפץ. והוי ככל קבלת תענית.