Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Date formatting issue when using var() (Read 3551 times)
Akiva R. Schoen
Full Member
*
Offline



Posts: 63
Seattle, WA
Date formatting issue when using var()
Sep 13th, 2012, 4:41pm
 
I have a user-created date Attribute called $PostedOn to which a date been assigned. I want to use this Attribute's value in some code by stuffing it into a var with some custom formatting. Let's say the value is '9/13/12 1:32 PM'.

For some reason,

Code:
var date(format($PostedOn, "y-M0-D")); 


and

Code:
var date($PostedOn.format("y-M0-D"); 


produce different output.

The latter produces the expected result: '2012-09-13' whereas the former produces '6/15/02 12:07 AM' which is obviously unexpected.

I have, in the past used 'format($Attribute, "format")' to produce the proper result outside of a var() so I was surprised that it didn't work. So, I was under the impression that those two calls were aliases of each other.

Am I wrong or is this possibly a bug?

[Edited to Add]:
Actually, scratch that: both formatting types are broken inside of a var(). I thought I had tested them both but I was wrong. So it looks like they are aliases of each other but are broken in var().
Back to top
 
« Last Edit: Sep 13th, 2012, 4:44pm by Akiva R. Schoen »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Date formatting issue when using var()
Reply #1 - Sep 13th, 2012, 5:10pm
 
On the road without a Mac so no TB. However, your second code sample has unmatched parentheses. Also, see here for var function syntax. Your examples are creating a variable called 'date' which is also the name of an action code function. I'd guess that's confused the parser. Have you tried:

var x date(format($PostedOn, "y-M0-D"));

Or

var x date($PostedOn.format("y-M0-D"));

Then use 'x' to fetch the variable. On an iPhone so can't test this code!
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Date formatting issue when using var()
Reply #2 - Sep 14th, 2012, 11:06am
 
Mark Anderson is correct in observing the collision between your var name and the date() function. But there's another problem in his correction.


date(...) converts a string to a date.

format(...) converts a date to a string.

So, you're undoing work you've just done. To make things more complicated, date(...) can't understand every conceivable date format; it knows some standard formats, and also knows your system date settings.  But that means your expression will have different results on different machines, if those machines use different locate date formats.
Back to top
 
 
WWW   IP Logged
Akiva R. Schoen
Full Member
*
Offline



Posts: 63
Seattle, WA
Re: Date formatting issue when using var()
Reply #3 - Sep 14th, 2012, 11:14am
 
That makes sense. I erroneously assumed that Tinderbox would sort out that I wanted a var called date and didn't want to call date() on a var that didn't have a name. It doesn't seem completely intuitive that Tinderbox would assume it was both the date function and the name of the var. If indeed that's what it's doing. It was allowing me to assign the var value of date to an Attribute which was interesting (and which was how I was seeing how it wasn't working as I expected it to).
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Date formatting issue when using var()
Reply #4 - Sep 17th, 2012, 8:19am
 
To round this out for later readers: don't use var names that match action code operators )or attribute names already defined**). Thus, any of these would have been better - assuming you intend a string-type variable value:

var thedate(format($PostedOn, "y-M0-D"));

var thedate;
thedate = format($PostedOn, "y-M0-D");

var thedate($PostedOn.format("y-M0-D"));

var thedate;
thedate = $PostedOn.format("y-M0-D");


** looking deeper - Tb is parsing the literal strings of the code you enter. Logically you want to avoid name collisions between action &  export codes and system user attributes. Otherwise, you're forcing TB to contextually guess whether X is a var name, a code name or an attribute - thus the deliberately non-attribute style name 'thedate'. That said, if you stick with simple var names, likely you'll never trip on this, though for the more experienced TB (or other app) code, my take on this is to treat action/export codes and current attributes as reserved words in a code context.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print