Blog · November 2026 · 8 min read Blog · Novembre 2026 · 8 min de lectureالمدونة · نوفمبر 2026 · 8 دقائق قراءة

A garden that grows with your health, and the date bugs hiding in it Un jardin qui pousse avec votre santé, et les bugs de dates cachés dedansحديقة تنمو مع صحتك، وأخطاء التواريخ المختبئة فيها

Diab turns diabetes care into a garden: healthy days earn plants. We built it with Expo at a hackathon, I later brought it to the web, and rereading it I found that almost every bug was about the same thing: what "today" means. Diab transforme le suivi du diabète en jardin : les journées saines font gagner des plantes. Nous l'avons construit avec Expo pendant un hackathon, je l'ai ensuite porté sur le web, et en le relisant, j'ai vu que presque tous les bugs portaient sur la même chose : ce que veut dire « aujourd'hui ».يحوّل Diab متابعة السكري إلى حديقة: الأيام الصحية تكسبك نباتات. بنيناه بـ Expo خلال هاكاثون، ثم نقلته لاحقاً إلى الويب، وعند إعادة قراءته وجدت أن كل الأخطاء تقريباً تدور حول الشيء نفسه: ماذا تعني كلمة «اليوم».

The ideaL'idéeالفكرة

Living with diabetes means tracking glucose, food, water, walking, sleep and a long list of appointments, every day, for years. The hard part is not the tracking, it is staying motivated. At the PEXILIS Hackathon (Open Mind Club, February 2026), our team built Diab: a React Native app where good habits earn plants for a personal garden. Balanced glucose for a day gives an Aloe Vera; a week of walking gives a lavender field. Vivre avec le diabète, c'est suivre la glycémie, l'alimentation, l'eau, la marche, le sommeil et une longue liste de rendez-vous, tous les jours, pendant des années. Le plus dur n'est pas de noter, c'est de rester motivé. Au hackathon PEXILIS (Open Mind Club, février 2026), notre équipe a construit Diab : une appli React Native où les bonnes habitudes font gagner des plantes pour un jardin personnel. Une glycémie équilibrée pendant une journée donne un aloe vera ; une semaine de marche donne un champ de lavande.العيش مع السكري يعني متابعة السكر في الدم، والأكل، والماء، والمشي، والنوم، وقائمة طويلة من المواعيد، كل يوم، لسنوات. والصعب ليس التسجيل، بل البقاء متحفزاً. في هاكاثون PEXILIS (نادي Open Mind، فيفري 2026)، بنى فريقنا Diab: تطبيق React Native تكسبك فيه العادات الجيدة نباتات لحديقتك الخاصة. سكر متوازن ليوم كامل يمنحك صبّاراً (ألوفيرا)، وأسبوع من المشي يمنحك حقل خزامى.

Everything the garden measures comes from what the user enters, so there is no point in cheating: the garden only reflects your own effort. Tout ce que mesure le jardin vient de ce que l'utilisateur saisit : tricher ne sert à rien, le jardin ne reflète que ses propres efforts.كل ما تقيسه الحديقة يأتي مما يدخله المستخدم، فلا فائدة من الغش: الحديقة لا تعكس إلا جهدك أنت.

Offline first, with no backendHors ligne d'abord, sans backendدون اتصال أولاً، ودون خادم خلفي

Health data is personal, and a hackathon has no time for a server. So the app has no backend at all: each part of the state (records, daily tasks, goals, achievements, garden) is a small Zustand store, saved automatically to the phone's storage with the persist middleware. Les données de santé sont personnelles, et un hackathon ne laisse pas le temps de faire un serveur. L'appli n'a donc aucun backend : chaque partie de l'état (mesures, tâches du jour, objectifs, succès, jardin) est un petit store Zustand, sauvegardé automatiquement dans le stockage du téléphone grâce au middleware persist.البيانات الصحية شخصية، والهاكاثون لا يترك وقتاً لبناء خادم. لذلك لا يملك التطبيق أي خادم خلفي: كل جزء من الحالة (القياسات، ومهام اليوم، والأهداف، والإنجازات، والحديقة) مخزن Zustand صغير، يُحفظ تلقائياً في ذاكرة الهاتف عبر الوسيط persist.

export const useTaskStore = create<TaskStore>()(
  persist(
    (set, get) => ({
      tasks: defaultTasks,
      currentDate: todayString(),
      history: [],          // days where every task was done
      toggleTask: (id) => set(/* ... */),
      checkForDayReset: () => set(/* ... */),
    }),
    { name: "daily_tasks", storage: createJSONStorage(() => AsyncStorage) },
  ),
);

Daily tasks and streaksLes tâches du jour et les sériesمهام اليوم والسلاسل

Daily tasks ("take medication", "check fasting glucose", "10-minute walk") must reset every day, without any server to run a midnight job. The trick is a lazy reset: the store remembers the date it belongs to, and when the app opens, if that date is not today, every task is unchecked. When all tasks are done, the day is added to a history list. Les tâches du jour (« prendre son traitement », « glycémie à jeun », « marche de 10 minutes ») doivent se remettre à zéro chaque jour, sans serveur pour lancer une tâche à minuit. L'astuce, c'est une remise à zéro paresseuse : le store retient la date à laquelle il correspond, et à l'ouverture de l'appli, si cette date n'est pas aujourd'hui, toutes les tâches sont décochées. Quand toutes les tâches sont faites, la journée est ajoutée à un historique.يجب أن تعود مهام اليوم («تناول الدواء»، «قياس السكر صائماً»، «مشي 10 دقائق») إلى الصفر كل يوم، دون خادم يشغّل مهمة عند منتصف الليل. والحيلة هي إعادة ضبط كسولة: يحفظ المخزن التاريخ الذي يخصه، وعند فتح التطبيق، إذا لم يكن هذا التاريخ هو اليوم، تُلغى علامة كل المهام. وعند إنجاز كل المهام، يُضاف اليوم إلى قائمة السجل.

Streaks are then computed, never stored: start from today and walk back one day at a time while the day meets its goal. Achievements work the same way, as small functions over the records, registered by type: Les séries sont ensuite calculées, jamais stockées : partir d'aujourd'hui et reculer d'un jour à la fois tant que la journée atteint son objectif. Les succès fonctionnent pareil, comme de petites fonctions sur les mesures, enregistrées par type :ثم تُحسب السلاسل ولا تُخزَّن أبداً: نبدأ من اليوم ونرجع يوماً بيوم ما دام اليوم يحقق هدفه. والإنجازات تعمل بالطريقة نفسها، كدوال صغيرة على القياسات، مسجّلة حسب النوع:

const achievementEvaluators: Record<AchievementType, GoalEvaluator> = {
  PERFECT_DAY: (_, { api }) => {
    const metrics = ["Activity", "Daily", "Water", "Sleep", "Glucose", "Diet"];
    const done = metrics.filter((m) => api.getMetricStreak(m) >= 1).length;
    return { completion: done === metrics.length, progress: done / metrics.length };
  },
  GLUCOSE_REBALANCE: /* ... */,
};

Returning a progress between 0 and 1, and not just done or not done, lets the screen show "4 of 6" and keeps people going. Renvoyer une progress entre 0 et 1, et pas seulement fait ou pas fait, permet à l'écran d'afficher « 4 sur 6 » et donne envie de continuer.إرجاع قيمة progress بين 0 و1، لا مجرد «تم» أو «لم يتم»، يسمح للشاشة بعرض «4 من 6» ويشجع على المواصلة.

Bringing a React Native app to the webPorter une appli React Native sur le webنقل تطبيق React Native إلى الويب

A hackathon app that only runs in Expo Go on someone's phone is hard to show on a CV. Months later, I made a web version, since Expo already ships react-native-web. The export built fine, but in the browser the app never really started: the first screen stayed stuck, the forms did nothing, and the console showed one error: Cannot use 'import.meta' outside a module. Zustand's middleware contains import.meta.env, and the web bundle is not loaded as a module. The Expo Babel preset can rewrite import.meta, but only does it for server code by default, so one option fixed it without touching the app: Une appli de hackathon qui ne tourne que dans Expo Go sur le téléphone de quelqu'un est difficile à montrer sur un CV. Des mois plus tard, j'en ai fait une version web, puisque Expo inclut déjà react-native-web. L'export se construisait sans erreur, mais dans le navigateur l'appli ne démarrait jamais vraiment : le premier écran restait bloqué, les formulaires ne faisaient rien, et la console affichait une seule erreur : Cannot use 'import.meta' outside a module. Le middleware de Zustand contient import.meta.env, et le bundle web n'est pas chargé comme un module. Le preset Babel d'Expo sait réécrire import.meta, mais par défaut seulement pour le code serveur : une seule option a tout réglé, sans toucher à l'appli :تطبيق هاكاثون لا يعمل إلا في Expo Go على هاتف أحدهم يصعب عرضه في سيرة ذاتية. بعد أشهر، صنعت له نسخة ويب، لأن Expo يتضمن أصلاً react-native-web. كان التصدير يُبنى دون خطأ، لكن التطبيق لم يشتغل فعلاً في المتصفح: بقيت الشاشة الأولى عالقة، ولم تفعل الاستمارات شيئاً، وظهر خطأ واحد في الكونسول: Cannot use 'import.meta' outside a module. يحتوي وسيط Zustand على import.meta.env، وحزمة الويب لا تُحمَّل كوحدة (module). ويستطيع إعداد Babel الخاص بـ Expo إعادة كتابة import.meta، لكن افتراضياً لشيفرة الخادم فقط، فأصلح خيار واحد كل شيء دون لمس التطبيق:

// babel.config.js
module.exports = function (api) {
  api.cache(true)
  return {
    // zustand's middleware uses import.meta, which the web bundle cannot run as-is
    presets: [["babel-preset-expo", { unstable_transformImportMeta: true }]],
  }
}

The second surprise: Expo's static output pre-renders every page at build time, where there is no localStorage. In the browser, the stores then load the saved data and the screen no longer matches the HTML, which React reports as a hydration mismatch. For an app whose whole content lives in the user's browser, pre-rendering brings nothing, so the web build became a single-page app ("output": "single" in app.json) with a Vercel rewrite sending every URL to index.html. Deuxième surprise : la sortie statique d'Expo pré-affiche chaque page au moment du build, là où il n'y a pas de localStorage. Dans le navigateur, les stores chargent ensuite les données sauvegardées et l'écran ne correspond plus au HTML, ce que React signale comme une erreur d'hydratation. Pour une appli dont tout le contenu vit dans le navigateur de l'utilisateur, le pré-affichage n'apporte rien : le build web est donc devenu une application d'une seule page ("output": "single" dans app.json), avec une réécriture Vercel qui envoie toutes les URL vers index.html.المفاجأة الثانية: المخرجات الثابتة في Expo تعرض كل صفحة مسبقاً وقت البناء، حيث لا يوجد localStorage. ثم في المتصفح، تحمّل المخازن البيانات المحفوظة فلا تعود الشاشة مطابقة لـ HTML، وهو ما يعلنه React كخطأ في الإماهة (hydration). وفي تطبيق يعيش كل محتواه في متصفح المستخدم، لا يضيف العرض المسبق شيئاً، فصار بناء الويب تطبيقاً من صفحة واحدة ("output": "single" في app.json)، مع إعادة توجيه في Vercel ترسل كل الروابط إلى index.html.

Five date bugsCinq bugs de datesخمسة أخطاء في التواريخ

Rereading the code for this article, I noticed that the bugs were not in the garden, the UI or the state. They were almost all about dates. En relisant le code pour cet article, j'ai remarqué que les bugs n'étaient ni dans le jardin, ni dans l'interface, ni dans l'état. Ils portaient presque tous sur les dates.عند إعادة قراءة الشيفرة لهذا المقال، لاحظت أن الأخطاء لم تكن في الحديقة ولا في الواجهة ولا في الحالة. كانت كلها تقريباً في التواريخ.

1. Two dates are never equal with ===1. Deux dates ne sont jamais égales avec ===1. تاريخان لا يتساويان أبداً بـ ===

The "Recovery" achievement rewards bringing fasting glucose back into range after a bad day. To find yesterday's measurements, the code did this: Le succès « Recovery » récompense le retour d'une glycémie à jeun dans la norme après une mauvaise journée. Pour trouver les mesures d'hier, le code faisait ceci :يكافئ إنجاز «Recovery» إعادة السكر الصائم إلى المجال الطبيعي بعد يوم سيئ. ولإيجاد قياسات الأمس، كانت الشيفرة تفعل هذا:

recordings.filter((r) => new Date(r.date) === yesterday)   // always false

// compare calendar days instead
recordings.filter((r) => dayKey(new Date(r.date)) === dayKey(yesterday))

=== compares two objects by reference, and a new Date is always a new object, so the filter always returned nothing and the achievement could never be unlocked. TypeScript accepted it without a word. (The data fetch above it also only asked for the last 24 hours of records, which covers only part of yesterday.) === compare deux objets par référence, et une nouvelle Date est toujours un nouvel objet : le filtre ne renvoyait donc jamais rien, et le succès ne pouvait jamais être débloqué. TypeScript l'a accepté sans rien dire. (La lecture des données juste au-dessus ne demandait en plus que les mesures des dernières 24 heures, qui ne couvrent qu'une partie d'hier.)=== تقارن كائنين حسب المرجع، وDate الجديد كائن جديد دائماً، لذا لم يُرجع المرشّح أي شيء أبداً، ولم يكن ممكناً فتح الإنجاز قط. وقَبِل TypeScript ذلك دون أي تنبيه. (كما أن قراءة البيانات فوقه مباشرة لم تطلب إلا قياسات آخر 24 ساعة، وهي لا تغطي إلا جزءاً من الأمس.)

2. "Today" in UTC is not today in Algiers2. « Aujourd'hui » en UTC n'est pas aujourd'hui à Alger2. «اليوم» بتوقيت UTC ليس اليوم في الجزائر

Every day key came from new Date().toISOString().split("T")[0]. toISOString() is always in UTC, and Algeria is UTC+1. Between midnight and 1 a.m., the app still thinks it is yesterday: a task done at 00:30 counts for the previous day, and the daily reset happens at 1 a.m. instead of midnight. In timezones further from UTC, the gap is several hours. The fix is one helper that builds the key from the local date (getFullYear, getMonth, getDate), used everywhere. Chaque clé de jour venait de new Date().toISOString().split("T")[0]. toISOString() est toujours en UTC, et l'Algérie est en UTC+1. Entre minuit et 1 h du matin, l'appli croit encore être la veille : une tâche faite à 0 h 30 compte pour le jour d'avant, et la remise à zéro quotidienne se fait à 1 h au lieu de minuit. Dans des fuseaux plus éloignés de UTC, l'écart est de plusieurs heures. La correction : une seule fonction qui construit la clé à partir de la date locale (getFullYear, getMonth, getDate), utilisée partout.كان كل مفتاح يوم يأتي من new Date().toISOString().split("T")[0]. وtoISOString() دائماً بتوقيت UTC، والجزائر في UTC+1. بين منتصف الليل والساعة الواحدة صباحاً، يظن التطبيق أننا ما زلنا في الأمس: المهمة المنجزة على الساعة 00:30 تُحسب لليوم السابق، وتحدث إعادة الضبط اليومية على الواحدة بدل منتصف الليل. وفي مناطق زمنية أبعد عن UTC، يصل الفرق إلى عدة ساعات. والتصحيح: دالة واحدة تبني المفتاح من التاريخ المحلي (getFullYear وgetMonth وgetDate)، تُستعمل في كل مكان.

3. Midnight passes while the app is open3. Minuit passe pendant que l'appli est ouverte3. يمر منتصف الليل والتطبيق مفتوح

The lazy reset runs once, when the app starts. A phone keeps apps alive in the background for days, so someone who opens Diab in the morning may still see yesterday's ticked tasks. Running the same check when the app comes back to the foreground (React Native's AppState) fixes it. La remise à zéro paresseuse ne tourne qu'une fois, au démarrage de l'appli. Un téléphone garde les applis en arrière-plan pendant des jours : quelqu'un qui ouvre Diab le matin peut encore voir les tâches cochées de la veille. Lancer la même vérification quand l'appli revient au premier plan (AppState de React Native) règle le problème.لا تعمل إعادة الضبط الكسولة إلا مرة واحدة، عند تشغيل التطبيق. والهاتف يُبقي التطبيقات في الخلفية لأيام، فمن يفتح Diab صباحاً قد يرى مهام الأمس مؤشَّراً عليها. وتشغيل الفحص نفسه عند عودة التطبيق إلى الواجهة (AppState في React Native) يحل المشكلة.

4. Every streak is 0 in the morning4. Toutes les séries valent 0 le matin4. كل السلاسل صفر في الصباح

Streaks start counting from today. Before the first glass of water is logged, today fails its goal, the loop stops at once, and a 20-day streak shows 0. The usual rule: if today has no data yet, start counting from yesterday, and only break the streak once a full day was missed. Les séries commencent à compter à partir d'aujourd'hui. Avant le premier verre d'eau noté, aujourd'hui n'atteint pas son objectif, la boucle s'arrête tout de suite, et une série de 20 jours affiche 0. La règle habituelle : si aujourd'hui n'a pas encore de données, commencer à compter à partir d'hier, et ne casser la série qu'une fois une journée entière manquée.تبدأ السلاسل العد من اليوم. وقبل تسجيل أول كوب ماء، لا يحقق اليوم هدفه، فتتوقف الحلقة فوراً، وتظهر سلسلة من 20 يوماً كصفر. والقاعدة المعتادة: إذا لم تكن لليوم بيانات بعد، نبدأ العد من الأمس، ولا نكسر السلسلة إلا بعد فوات يوم كامل.

5. Goals read once, at startup5. Des objectifs lus une seule fois, au démarrage5. أهداف تُقرأ مرة واحدة عند التشغيل

The class that computes streaks copied the personal goals from the store when it was created: private personalGoals = usePersonalGoalStore.getState().goals. Change your water goal, and streaks keep using the old one until the app restarts. Reading the store at the moment of the calculation keeps a single source of truth. La classe qui calcule les séries copiait les objectifs personnels depuis le store au moment de sa création : private personalGoals = usePersonalGoalStore.getState().goals. Changez votre objectif d'eau, et les séries continuent d'utiliser l'ancien jusqu'au redémarrage de l'appli. Lire le store au moment du calcul garde une seule source de vérité.كان الصنف الذي يحسب السلاسل ينسخ الأهداف الشخصية من المخزن لحظة إنشائه: private personalGoals = usePersonalGoalStore.getState().goals. غيّر هدفك من الماء، وستواصل السلاسل استعمال الهدف القديم حتى إعادة تشغيل التطبيق. وقراءة المخزن لحظة الحساب تُبقي مصدراً واحداً للحقيقة.

What I would do differentlyCe que je ferais autrementما كنت سأفعله بشكل مختلف

  • One date module. A single dayKey() in local time, a single isSameDay(), and a lint rule against toISOString().split. Most of the bugs above disappear.Un seul module de dates. Une seule fonction dayKey() en heure locale, un seul isSameDay(), et une règle de lint contre toISOString().split. La plupart des bugs ci-dessus disparaissent.وحدة واحدة للتواريخ. دالة dayKey() واحدة بالتوقيت المحلي، وisSameDay() واحدة، وقاعدة lint تمنع toISOString().split. وتختفي معظم الأخطاء المذكورة أعلاه.
  • Tests with a fake clock. Date logic is easy to test if "now" can be injected: 23:59, 00:30, a month change, a missed day. None of these bugs survives such a test.Des tests avec une fausse horloge. La logique de dates est facile à tester si on peut injecter « maintenant » : 23 h 59, 0 h 30, un changement de mois, un jour manqué. Aucun de ces bugs ne survit à ce genre de test.اختبارات بساعة وهمية. منطق التواريخ سهل الاختبار إذا أمكن حقن «الآن»: 23:59، و00:30، وتغيّر الشهر، ويوم فائت. ولا ينجو أي من هذه الأخطاء من اختبار كهذا.
  • Finish the garden's rules. The design lists eight plants; in the hackathon build, two achievements are wired to real rules. The evaluator registry makes each new one a single function.Terminer les règles du jardin. La conception prévoit huit plantes ; dans la version du hackathon, deux succès sont reliés à de vraies règles. Le registre d'évaluateurs fait de chaque nouveau succès une seule fonction.إكمال قواعد الحديقة. يتضمن التصميم ثمانية نباتات؛ وفي نسخة الهاكاثون، إنجازان فقط مربوطان بقواعد حقيقية. وسجل دوال التقييم يجعل كل إنجاز جديد دالة واحدة.

TakeawaysÀ retenirالخلاصة

  • Offline-first is cheap with Zustand and persist, and it is the most private choice for health data.Le hors-ligne d'abord ne coûte pas cher avec Zustand et persist, et c'est le choix le plus respectueux de la vie privée pour des données de santé.العمل دون اتصال أولاً رخيص مع Zustand وpersist، وهو الخيار الأكثر احتراماً للخصوصية في البيانات الصحية.
  • Compute streaks from history instead of storing counters: there is nothing to keep in sync.Calculer les séries à partir de l'historique au lieu de stocker des compteurs : il n'y a rien à garder synchronisé.احسب السلاسل من السجل بدل تخزين العدّادات: لا يوجد شيء يجب مزامنته.
  • "Today" is a decision: local time, one helper, tested with a fake clock.« Aujourd'hui » est une décision : heure locale, une seule fonction, testée avec une fausse horloge.«اليوم» قرار: توقيت محلي، ودالة واحدة، مختبرة بساعة وهمية.
  • A web demo turns a hackathon project into something anyone can open in ten seconds.Une démo web transforme un projet de hackathon en quelque chose que n'importe qui peut ouvrir en dix secondes.العرض على الويب يحوّل مشروع هاكاثون إلى شيء يستطيع أي شخص فتحه في عشر ثوانٍ.

Try the live demo (best in mobile view; sign up with any details, everything stays in your browser), or read the code on GitHub. Essayez la démo en ligne (idéale en affichage mobile ; inscrivez-vous avec n'importe quelles informations, tout reste dans votre navigateur), ou lisez le code sur GitHub.جرّب العرض المباشر (الأفضل بعرض الهاتف؛ سجّل بأي معلومات، كل شيء يبقى في متصفحك)، أو اقرأ الشيفرة على GitHub.