-
Notifications
You must be signed in to change notification settings - Fork 8
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
88f99a8
common: support custom formatter on cursor
josephjclark b67f81b
surveycto: add new cursor function
josephjclark 64c8670
surveycto: docs
josephjclark a9327ef
surveycto: add logging
josephjclark 49e72a7
remove comment
josephjclark 8f425ad
format
josephjclark ab5de66
surveycto: fix jsdoc
josephjclark ee7da7d
surveycto: linter fixes
josephjclark 52699be
Merge branch 'main' into cursor-surveycto
josephjclark 9e913fd
surveyCTO: tweak docs
josephjclark 2df5888
version bumps
josephjclark e892ccb
lockfile
josephjclark File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@openfn/language-surveycto': minor | ||
--- | ||
|
||
Extend the cursor function to support surveyCTO string format dates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@openfn/language-common': patch | ||
--- | ||
|
||
cursor: support format option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { | |
logResponse, | ||
makeBasicAuthHeader, | ||
} from '@openfn/language-common/util'; | ||
import { formatInTimeZone } from 'date-fns-tz'; | ||
|
||
const addBasicAuth = (configuration = {}, headers) => { | ||
const { username, password } = configuration; | ||
|
@@ -50,3 +51,43 @@ export const requestHelper = (state, path, params, callback = s => s) => { | |
throw err; | ||
}); | ||
}; | ||
|
||
export const dateRegex = /^(\w{3} \d{2}, \d{4} \d{2}:\d{2}(:\d{2})? (PM|AM))$/; | ||
|
||
/** | ||
* This function will attempt to convert any date representation into | ||
* a surveyCTO `MMM dd, yyy h:mm:ss a` string. | ||
* Strings already in this format will be ignored, other strings will be parsed | ||
* by the Date constructor. | ||
* Number values should be epoch or unix timestamps and will be converted to strings | ||
* @param {*} date a date in a string, number or Date format | ||
* @returns | ||
*/ | ||
export const convertDate = date => { | ||
// If it's already in the right format, return it | ||
if (typeof date === 'string' && dateRegex.test(date)) { | ||
return date; | ||
} | ||
|
||
// Otherwise parse the input into a new date object | ||
let dateObj = date; | ||
if (typeof date === 'string' || typeof date === 'number') { | ||
if (/^\d{10}$/.test(date)) { | ||
// If the incoming date is a unit timestamp, just return it | ||
dateObj = new Date(date * 1000); | ||
} else { | ||
dateObj = new Date(date); | ||
} | ||
} | ||
|
||
// And return in the correct formatting (utc time) | ||
const formatted = formatInTimeZone( | ||
dateObj.toISOString(), | ||
'UTC', | ||
'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 commentThe 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! |
||
|
||
return formatted; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.