New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
surveycto: add new cursor #524
Conversation
*/ | ||
|
||
/** | ||
* Fetch form submissions | ||
* @example <caption>Fetch all form submissions</caption> | ||
* fetchSubmissions('test'); | ||
* @example <caption> With `MMM dd, yyyy h:mm:ss a` date format</caption> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These examples have been trimmed down so that each one only shows one thing. Ie, the CSV example doesn't include a date.
'MMM dd, yyy h:mm:ss a' | ||
); | ||
|
||
console.log(`Converted timestamp "${date}" to "${formatted}" (UTC)`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this as an afterthought because it seems quite important 🤔
On the other hand it's noisy and maybe a bit defensive. Opinions welcome!
This comment was marked as outdated.
This comment was marked as outdated.
Hi @mtuchi I think this will be interesting to you - do you have time to take a look today? |
I ran
|
Thank you @mtuchi , that's fine, we still need to do the release engineering stuff. I'm more interested in whether this behaviour is as useful as I hope it is! |
The cursor is working but i am seeing these double logs with the cursor
When i run the following code
My gut tells me the cursor should also tell me the date in |
I like that it converts the time to UTC first
Will log
|
What's your thought on supporting something like this ?
|
Hmm, yeah the logging is tricky because it's hard to set context. I'll think about it because the logs are definitely too verbose right now. What would be your expected behavour for this?
To write state.cursor as What would the utility of that be? |
I guess the use case is setting the
|
I am not sure if a user specify a unix timestamp, we should convert it to UTC?
I guess it doesn't hurt making sure the timestamp is in UTC 🤷🏽 . Also if i am in UTC timezone i don't think we need to convert the time to UTC right ? |
Users can still pass unix timestamps in. We'll still convert them for strings, which gives clearer logs. We could choose to leave unix timestamps alone but the idea of all of this for the So this works fine: Don't get hunt up on "converting to UTC", the point is more that we convert to String. Unix and Epoch timestamps are always in UTC, so we're basically just stringifying them for readability. |
Okay got you 👍🏽 Regarding
I have tried both number and string and it worked
|
@mtuchi I think this is ready for release and we're both happy with it? Would you mind giving it an approval before I merge? Sadly because I've touched common all the adaptors have been bumped, even thouhh they're unaffected (only adaptors exporting cursor are affected). I've raised an issue to look into this but tbh I think it's a neccessary evil |
@josephjclark you can go ahead build & push tags then squash merge this pr |
Summary
This PR adds:
format
function in the common cursorcursor
exported bysurveycto
Issues
Closes #520
Simplified Date handling
The
date
option infetchSubmissions
can now accept a surveyCTO date, an epoch or unix timestamp, or basically anything you can pass into new Date(). This has been documented lightly in a way that encourages the CTOMMM dd, yyy h:mm:ss a
format, but doesn't prescribe it.The "magic" is handled by a little function which takes a date value and guarantees to return a string formatted in the surveyCTO way.
Why settle on this format? Because it's quite human readable, so when queries get printed in the log, you can see the actual parameters without having to do the maths on the timestamp.
I also think it's important for openfn users who aren't surveyCTO experts to be able to use dates in the way they expect. Just pass a date into the date property - we'll figure out the formatting. Life's too short to worry about this stuff.
Documentation has been updated and simplified to this effect.
The actual support for this is implemented in
fetchSubmissions
and the newcursor
function.common.cursor.format
The new format function in common allows you to intercept the cursor value just before it gets written to state, so that you can specifier your own formats (or even values). It's more than a formatter tbh but its usage feels quite intuitive as a
format
(as opposed toparse
or something).See the docs PR for usage: OpenFn/docs#479
surveycto.cursor
surveyCTO takes advantage of the new cursor functionality.
It exports its own
cursor
function with a formatter baked in. So when you pass a date intocursor
, what will actually be written to state is a surveyCTO style string.You can pass in
today
orApr 18, 2024 6:26:21 AM
or2024-04-23T15:49:31.764Z
and it'll all just work. The result is compatible withfilterSubmissions
.