mistql icon indicating copy to clipboard operation
mistql copied to clipboard

Dealing with dates

Open albinvll opened this issue 2 years ago • 6 comments

Hello, I am very interested to see how this project goes, the idea seems great and using it looks simple but powerful. However I ran into this problem when working with arrays with dates. Maybe there's something I haven't learned yet seeing as I'm as new to this as the language :^), but the Date Objects are empty. Good luck on this project! Rows

albinvll avatar Nov 01 '21 21:11 albinvll

Good find! I'd consider this an oversight / bug of the JS library implementation (the translation from JS types to MistQL types isn't yet robustly specified), but dates should almost certainly be translated as ISO 8601 compliant strings. Formalizing this will be incredibly useful to do.

An additional possibility is adding a core "date" type to MistQL, but honestly that would add a LOT of complexity, not just for the specification of the language, but the interface to it.

evinism avatar Nov 01 '21 22:11 evinism

My suggestion is to not assume a single date serialization format like 8601 and instead provide date helper functions that can be used to deal with all different types of date handling situations. SQLite's handling of date comes to mind. They don't actually have a date type but some functions that make it easy to deal with parsing and formatting dates.

cfilipov avatar Nov 01 '21 22:11 cfilipov

@cfilipov 100% agree -- to me it feels like the right choice is to lean on existing datatypes and leverage helpers to assist in date processing. The translation from JS Date type to MistQL would need to be standardized, which is where 8601 comes in.

evinism avatar Nov 01 '21 22:11 evinism

Going to adopt JSON.stringify behavior as my basis for conversion semantics from JS to MistQL. I can probably do that for other languages as well.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Edit: I thought a few of the translations would be a bit unintuitive, so I've changed them a little.

evinism avatar Nov 01 '21 23:11 evinism

Probably a good idea to keep this issue open, as we'll need at least a few date helpers.

evinism avatar Nov 04 '21 19:11 evinism

all but forgot about python here. Aiming to make date(2015, 1, 1) -> 2015-1-1 per iso, and have datetime map the same as it does in JS.

evinism avatar Apr 19 '22 06:04 evinism