Posts

Showing posts with the label Programming

Dates in JSON

What format is the right one in JSON? "Or best? Is there any sort of standard on this?" "DateTimes in JSON are hard. The problem comes from the JSON spec itself: there is no literal syntax for dates in JSON. The spec has objects, arrays, strings, integers, and floats, but it defines no standard for what a date looks like." A common date/time-format used is ISO 8601. It is also used widely in libraries such as JavaScript's toJSON-method and Json.NET . In principle this turns the DateTime string into: <YYYY-MM-DD>T<HH:MM>[:SS.SSS][[+|-]HH:MM[:SS]|Z] Example: { "lastPlayedDateTime": "2021-12-28T23:30:00+01:00" } What's the Z? Z depicts the shorthand notation for UTC times, e.g. "2009-02-15T00:00Z" . Sources: Serializing Dates in JSON StackOverflow What is the "right" JSON date format? Wikipedia on ISO 8601 toJSON-method JSON spec

Linked List vs Array

The advantage of a linked list data structure over a plain array is that you can easily insert new items to the linked list. There is a good example and analogy in this post : "You have some errands to do, so you grab a piece of paper and write: bank groceries drop off drycleaning Then you remember that you also need to buy stamps. Because of the geography of your town, you need to do that after the bank. You could copy your whole list onto a new piece of paper: bank stamps groceries drop off drycleaning or you could scribble on the one you had: bank ....... STAMPS groceries drop off drycleaning As you thought of other errands, you might write them at the bottom of the list, but with arrows reminding yourself what order to do them in. This is a linked list. It's quicker and easier than copying the whole list around every time you add something. Then your cell phone rings while you're at the bank "hey, I got the stamps, don't pick u...