The Shulchan Aruch · Orach Chayim
אורח חיים שמ״דOrach Chayim 344
Siman 344 of 697 in Orach Chayim — 2 se'ifim
הלכות שבתLaws of Shabbat· siman 344
Se’if 1א׳
הַהוֹלֵךְ בַּמִּדְבָּר וְאֵינוֹ יוֹדֵעַ מָתַי הוּא שַׁבָּת, מוֹנֶה שִׁבְעָה יָמִים מִיּוֹם שֶׁנָּתַן אֶל לִבּוֹ שִׁכְחָתוֹ וּמְקַדֵּשׁ הַשְּׁבִיעִי בְּקִדּוּשׁ וְהַבְדָּלָה. וְאִם יֵשׁ לוֹ מִמַּה לְּהִתְפַּרְנֵס, אָסוּר לוֹ לַעֲשׂוֹת מְלָאכָה כְּלָל עַד שֶׁיִּכְלֶה מַה שֶּׁיֵּשׁ לוֹ וְאָז יַעֲשֶׂה מְלָאכָה בְּכָל יוֹם, אֲפִלּוּ בַּיּוֹם שֶׁמְּקַדֵּשׁ בּוֹ, כְּדֵי פַּרְנָסָתוֹ מְצֻמְצֶמֶת. וּמֻתָּר לֵילֵךְ בּוֹ בְּכָל יוֹם, אֲפִלּוּ בַּיּוֹם שֶׁמְּקַדֵּשׁ בּוֹ.
The Law of Someone Who Is Wandering in the Desert on Shabbat. Contains 2 Seifim: One who is wandering in the desert and does not when is Shabbat, counts seven days from the day he realized he did not know, and sanctifies the seventh day with Kiddush and Havdalah. If one has sustenance, one is forbidden from doing any work whatsoever until he uses what he has, and thereafter one should do work each day, even on the day he sanctifies, to achieve minimal sustenance. One is permitted to walk every day, even on the day he sanctifies.
Se’if 2ב׳
הָיָה יוֹדֵעַ מִנְיַן יוֹם שֶׁיָּצָא בּוֹ, כְּגוֹן שֶׁיּוֹדֵעַ שֶׁהַיּוֹם יוֹם רְבִיעִי אוֹ יוֹם חֲמִישִׁי לִיצִיאָתוֹ אֲבָל אֵינוֹ יוֹדֵעַ בְּאֵיזֶה יוֹם יָצָא, מֻתָּר לַעֲשׂוֹת מְלָאכָה כָּל מַה שֶּׁיִּרְצֶה בְּיוֹם שְׁמִינִי לִיצִיאָתוֹ שֶׁבְּיוֹם כָּזֶה יָצָא מִבֵּיתוֹ, דִּבְוַדַּאי לֹא יָצָא בְּשַׁבָּת; וְכֵן בְּיוֹם ט"ו, וּבְיוֹם כ"ב, וְכֵן לְעוֹלָם.
If he knows how many days he has been walking, i.e. he knows that today is the fourth day or the fifth day since his departure, but he does not know on which day he left, he is permitted to do as much work as he wants on the eighth day since his departure, because on that day of the week he left his house, and he certainly did not leave on Shabbat, and so too on the fifteenth day and the twenty-second day, and so on.
Shulchan Aruch, Orach Chayim — Torat Emet 363 edition, via Sefaria — public domain
English: Sefaria Community Translation — CC0