FileMaker-JSON-Functions icon indicating copy to clipboard operation
FileMaker-JSON-Functions copied to clipboard

timestamps not encoded properly

Open dansmith65 opened this issue 10 years ago • 5 comments

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: https://github.com/dansmith65/FileMaker-JSON/issues/9

dansmith65 avatar Sep 25 '15 02:09 dansmith65

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 avatar Sep 25 '15 02:09 dansmith65

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.

jean-Phil avatar Mar 04 '16 15:03 jean-Phil

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" )
)

dansmith65 avatar Mar 04 '16 18:03 dansmith65

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.

chivalry avatar Mar 05 '16 04:03 chivalry

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.

jean-Phil avatar Mar 08 '16 03:03 jean-Phil