Skip to content
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

timestamps not encoded properly #34

Open
dansmith65 opened this issue Sep 25, 2015 · 5 comments
Open

timestamps not encoded properly #34

dansmith65 opened this issue Sep 25, 2015 · 5 comments
Labels

Comments

@dansmith65
Copy link
Owner

jsonO (
    jsonOp ( "ts" ; Get ( CurrentTimestamp ) )
)
// = { "ts":9/24/2015 7:29:01 PM }

it should return:

{ "ts":"9/24/2015 7:29:01 PM" }

Originally reported here: dansmith65/FileMaker-JSON#9

@dansmith65
Copy link
Owner Author

FYI: while encoding dates/timestamps can be done this way (once the bug is fixed), if your JSON needs to be read by anything but FileMaker then you may want to read this: http://stackoverflow.com/a/15952652

dansmith65 added a commit that referenced this issue Oct 5, 2015
dansmith65 added a commit that referenced this issue Oct 5, 2015
NOTE: timestamps, dates, and times are converted to numbers in FileMaker's
own internal number format. This is useful for parsing within FileMaker,
but not useful for interacting with other services that expect a standard
format like YYYY-MM-DD.
Currently, you must manually convert timestamps, dates, and times to
whatever standard format you need, if sending the JSON to a different
system that expects a particular format.
@jean-Phil
Copy link

Hi Dan!

Did you consider adding an optional third argument to jsonOp( key; value {; type } ), and a second to jsonGet( key { ; type } )? We would loose in succinctness, I grant you that, but this way, the functions could deal with timestamp and date conversions (to various standards, ie. ISO8601, unixTS, etc. ) without further external dependencies, since, as you mention, it is pretty much intrinsic to proper parsing from one language to the other? -- It would also allow properly converting boolean values... --

I would be happy to contribute, if you find that a viable solution.

@dansmith65
Copy link
Owner Author

If FileMaker allowed for optional parameters in custom functions, I would be all for adding this feature. But since it doesn't, I wouldn't want to change jsonOp( key; value ) to jsonOp( key; value; type ) because it would not be compatible with existing code.

If you wanted to add this feature, I think the most appropriate way would be to fork the repo and change the functions in your fork.

Personally, would deal with this type of conversion by writing a separate custom function for each format I want to convert to/from, like so:

$json = jsonO (
    jsonOp ( "ts" ; TimestampToUnix ( Get ( CurrentTimestamp ) ) )
) ;
$fmTS = TimestampFromUnix ( jsonGet ( $json ; "ts" ) )

P.S. I've addressed the issue of Boolean's via two reserved strings: "json:true" "json:false"

JsonO (
    jsonOp ( "bool-val-example" ; If ( $booleanVariable ; "json:true" ; "json:false" ) )
)

Similarly, I use a reserved string for null values as well: "json:null"

JsonO (
    jsonOp ( "null-val-example" ; "json:null" )
)

@chivalry
Copy link

chivalry commented Mar 5, 2016

Personally, I wouldn't want this built into the JSON functions. Timestamp conversion is useful outside of that narrow requirement.

@jean-Phil, you might like to take a look at the fm-library project, which has a few custom functions that you might be interested in.

  • tmsp.FormatTimestamp ( _timestamp; _format_string ) uses a string to format a timestamp similar to the Unix date command line tool (i.e., tmsp.FormatTimestamp ( Timestamp ( Date ( 3; 27; 15 ); Time ( 14; 3; 6 ) ) ;"%D %H:%m %p" ) = "03/27/15 14:03 PM").
  • tmsp.ToISO8601 ( _timestamp ) uses tmsp.FormatTimestamp to convert a FileMaker timestamp into ISO8601 while tmsp.FromISO8601 reverses the process (i.e., tmsp.ToISO8601 ( Timestamp ( Date ( 12 ; 1; 2015 ) ; Time ( 12 ; 34 ; 56 ) ) ) = "2015-12-01T20:34:56Z").

There are some dependencies, such as tmsp.UTCDifference, which calculates the timezone difference so it can provide a Zulu-based ISO format.

@jean-Phil
Copy link

Thank you both for your replies.

@chivalry, I will definitely look into your fm-library work.
@DanSmith, I like your "json:true", "json:false", "json:null" solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants