Skip to content

Instantly share code, notes, and snippets.

@jeanpaulsio
Created August 26, 2017 22:33
Show Gist options
  • Save jeanpaulsio/e534814f568a0c9a2b743fce0f493077 to your computer and use it in GitHub Desktop.
Save jeanpaulsio/e534814f568a0c9a2b743fce0f493077 to your computer and use it in GitHub Desktop.
Time Data Structure
/*
0 - Sunday
1 - Monday
2 - Tuesday
3 - Wednesday
4 - Thursday
5 - Friday
6 - Saturday
*/
data =
[
{
id: 2
date_as_string: "Next Tuesday"
times: [
{
id: 1
time_string: "8:00am"
},
{
id: 2
time_string: "8:30am"
},
]
},
{
id: 3
date_as_string: "Next Wednesday"
times: [
{
id: 1
time_string: "8:00am"
},
{
id: 2
time_string: "8:30am"
},
]
},
]
@jeanpaulsio
Copy link
Author

These things don't necessarily have to be called "id" - and normally i'm not big on assigning numbered values to things that correspond to strings - but this is strictly for displaying things in order

@jeanpaulsio
Copy link
Author

To put things in a little more perspective - i don't expect the data to come in already ordered:

      times: [
        { unique_id: 123, id: 1, time_string: "8:00am" },
        { unique_id: 456, id: 2, time_string: "8:30am" },
        { unique_id: 789, id: 3, time_string: "9:00am" },
        { unique_id: 111, id: 4, time_string: "9:30am" },
        { unique_id: 222, id: 5, time_string: "10:00am" },
        { unique_id: 333, id: 6, time_string: "10:30am" },
      ]

I imagine it's probably more like this:

      times: [
        { unique_id: 333, id: 6, time_string: "10:30am" },
        { unique_id: 456, id: 2, time_string: "8:30am" },
        { unique_id: 111, id: 4, time_string: "9:30am" },
        { unique_id: 789, id: 3, time_string: "9:00am" },
        { unique_id: 222, id: 5, time_string: "10:00am" }
        { unique_id: 123, id: 1, time_string: "8:00am" },
      ]

I still need a unique id for each of these values but I'm ok with ditching the "id" concept if we can guarantee that these times are spit out of the API in order

@Johnsalzarulo
Copy link

Well, I matched yours exactly AND made one that I think is better...

https://github.com/Johnsalzarulo/uvohealth#available-times-endpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment