Playing with Time

Or, specifically, DateTime in C# and Date() in JavaScript.

I haven’t written about my Spaced Repetition app in a while (or ever? dunno), so here’s an official update of where it is: the front talks to the back, and the back talks to the database. I can pull all facts, delete individual facts, and — as of today! — pull facts by specified date.

Which leads me to what I learned today: UTC time!

An Almost-Disastrous Start

Thank goodness for my Catalyte cohort pals. I went to them with a mild complaint yesterday — why are dates zero-indexed?! — and they set me straight. There’s no need to manipulate actual dates, when I can be using UTC time and adding milliseconds/hours to it as needed.

Wut?

Okay, so let me back up and explain what it is I’m trying to do. Basically, the meat of how this whole spaced repetition thing works is like so:

  • When a user visits the site (which really has to be once a day for this to work), facts whose review date match the current day are pulled from the database and presented to the user for review.
  • The user reviews one fact and its associated tidbit, and then rates how they think they did before moving on to the next fact. This rating changes their tier. If they feel they did great, the tier (that is, the days between reviewing the card) goes up. If they feel they need more practice, the tier goes down. As suggested by Jarrod, there will even be a facepalm option — the tier goes all the way back to 1, or daily review, if that one is selected.
  • When the rating is clicked, the fact’s review date is updated in the database. Based on the tier, I’ll add a certain number of days (or hours, or milliseconds, whatever) to the current date and pass that back as the date for next review.

See that bolded part? That’s the part I was struggling to wrap my head around. It was already going to be bad enough to deal with adding days to the ends of months and years. I hadn’t even gotten as far as updating it to UTC time, as it’s stored in the database. (And to be honest, I still haven’t. That’s work for another day!)

Today’s Work

So, today I did some nice full-stack work towards getting the tier functionality up and running. I started by fixing how the facts are pulled — I was having trouble figuring out how to match the day and month exactly (and tbh I should probably add in the year? I’ll have to think on that…) but then I figured out that I needed to dig in deeper: instead of matching f.ReviewDate to date, I had to specify .Day and .Month. (See below.)

Once I got that working (and did a lil woohoo success dance) it was time to see if I could pull said facts via a front-end request.

It took a hot minute to figure out how to get my request just right so that it would even be passed back properly, and it’s a bit of a mess right now, but here’s what I came up with:

Like I said — that part up there is a bit of a mess, because just pulling a date via Date() doesn’t yield UTC format. It’s just a fancy date/time string.

Work For Tomorrow

First, there’s gotta be a way to get the UTC backend format handed to me in Javascript, right? Maybe? Until then, I have to do the above acrobatics.

Beyond that, there’s still tier work to be done, and it’s all frontend. The next step is definitely to get the function in place that will allow the user to rate their recall of the fact and send a PUT request to change the ReviewDate in the backend.

After that, I’m going to figure out how to render each fact for recall individually — have like a progress bar at the bottom that shows how many facts they have to review and where they are. (This feels ~*complicated*~ and not super important).

So, those are the next few steps laid out for me. Here I go!

3

mins
read

Begin typing your search above and press return to search. Press Esc to cancel.