check if an item is a date

MisterX b.xavier at internet.lu
Thu Mar 17 13:41:41 EST 2005


> This is nothing new, Xavier,
> 
> >But surprise!
> >

Thanks Rob! 

I went lengthy on this but you'll laugh at the situation and irony I
hopefully managed to write (ed.) ;) 

I, well, no, "we" all know RunRev can't handle all date formats... But
compounded issues in this one little report I tried to write "in all
simplicity" caused quite a few delays and script detours that weren't
pleasing - no crashes, the application (MC) required over 300MBs or ram for
the job, no prob! Just a few gui things that since MC haven't been looked
at... The wiser we are now, the better we'll fare I hope. But here's the
thing which im glad is over... So follows a few tips and revsuggestions too
to make the story much more palatable!

I think I got more than one thing to contend with... And plenty of
solutions... Consider Rev is an enterprise tool with SQL and shell being key
features. Unlike most, I use Xtalk (mc in this case - bugs confirmed in rev
later at home) to administer status of over 300 servers and a few big
hardisks for our projects, users, etc... bla bla bla (im not boasting, it is
just my situation and scale of things going on). Im fighting against all dos
or unix admins here and it's not always easy to put their mouth back where
it belongs - i have never failed a job, alert or project yet though and all
in time Thanks to MC!!! Im upgrading to Rev as soon as i get the approval at
work - that's another battle...) Anyway, in this industrious enterprise,
Xtalk makes data talk and it's awesome to make GUIs out of any shell
accessible tool needed to manage users, shares, servers, services, disks,
etc... Compared to batches! Your way instead of MS's way is a better way any
day right? 

That's for the MC and Rev PR customer experience bit! It just works! ;)

Rob, I would gladly try your seredipitous lib but I got a list of 33 million
dates to check (filtered from a 1 GB file in 6 hours! ;)... A zillion lines
of 1 date, 1 frequency, 1 sum (to sumarize). All three are possible dates!
And I got 3 other dimensions to corelate too later (aich! weekend job for a
few servers to munch on cluster style stack agents! ;)) I know I should do
this in PERL or C... But it's a one time job, no major hurry! I could also
reuse this for backup tape usage reports too but netbackup has a zillion
formating switches which can be used for formatting the date the right way
;) Some tools are just built right - unix is the best here! This particular
backup tool we use has more shell features than gui features could be packed
everywhere! Amazingly clean GUI! 

Anyway the list... Algorithimically i resorted to enforcing a date format,
items, etc... Good thing it was DOS dates but since I change hosts often the
date format changes too from US to EU... The day of the object was
irrelevant so... I put 1 into it! Cheap and dirty sugar for the interpreter,
sort, etc... (Note the final format is MM/YY... set the numberformat to
"0/0" and sort numeric - quick and dirty) 

The report's problems was later compounded by DOS dates read from a unix cif
mass storage device and there's plenty of errors or 1936 dates for
example... Im correcting everyone's exceptions here to give a "good" report
out! In 2005 top technology environment - unbelievable! if cars ran like
computer run... As Jaquie would say, cars would run after dogs and cats ;)

Second problem: date years are not sorted correctly...

Fixed with the centurycuttoff set at 0, years were already at 4 chars - now,
that's a good default for general or business use than computer dates...
Also much faster than emulating another date format conversion... Let's
laugh... OK, I know computer time in 1970 dates are important... but none
the less, being affected by this for example is like being hit by the y2k
bug - potentially anytime you're not careful! I can't afford mistakes in
this case - top management asked for this one report. 

I figured that seconds would be the reason this bug would think it's a date
but let's get real! the seconds is a time! Not a date mate. Ask anyone not
involved with RunRev... Ask the manager who asked that report... uh, I
wouldn't! ;) 

Playing with words or reality?

The bug solution is not in the is a date function... Although that would be
welcome fix if we all agree it's a good thing to keep a script language
close to human reality instead of ephemeral cyber reality called xtalk.
Human vs machine language, you know. 

The real issue is in fact what makes XTalk so much fun: No type casting!

Type Casting is a lower level language requirement to make variables
compatible among themselves. Read any C introduction on variables and
operators. It does have inate speed advantages and I think the transcript
interpreter does use this at times - it's a good tip to know what is being
"converted" by RunRev... Get the seconds is a string or a number or a date
object? These are things that would be helpfull for optimizing scripts ;)
Richard Gaskin has a benchmark stack (and so do i ;) but testing all
possibilities is rather less productive than finding that harmless info...

For example:
get item 3 of fld 3 -- "it" is a string variable
add 0 to it -- "it" is a number format variable now
if you computer using the number format thereafter in a loop, it's much
faster (untested but it's the way I remember I read how the HC interpreter
worked.

So the lack of typecasting is in itself a weakness for these cases... Anyone
with a long list of items will give up soon in consideration with quantity
analysis or database reporting (to mention a general admin, business, DBA
operation). The solution is often an extra check that takes lots of
processing (even if called by externals)... I wouldn't make a new external
each time I have a different list to sort! I haven't see the excellent
Rinaldi FullSort external for PC either ;( 

The problem is that we are missing in RunRev a (quick) way to cast-type
information previous to operations.

In C you must convert a real to an int to use a comparison operator like

  real myvar = 5.01;
  int  foobar = 3;
  if ( (int) myvar = foobar ) ...

In this example, it's simple but the point it there. The xtalk will convert
(or typecast) one number format into another. 

In the case of dates, we have to build "infrastructural" functions to handle
reality in code for a "generalized" approach (daunting task I agree
Jackie)... But sorry Jackie, but cats and dogs are not allowed in enterprise
reports leatherhead ;( It would make them more humane though ;)) 

Back to dates...

It could be interesting if the numberformat had a few related functions like
dateformat to enforce date formats and operators like is a (and others
naturally)... Read the numberformat once in a while, it's good to know to
avoid some nasty but fortunately documented surprises!

For example, business reports or price lists or catalogs (even online ones)
would get the benefit of easy currency format conversions!

Also handy for quick user input formats checking... is it
therequestedFormat? try again... quick and easy!

Take the table type report with currency displayed. Or a detailed filelist!
It's very taxing to convert that to a nice format or read it back for
analysis in some cases! For the HotKeyN2O I have to keep track of the events
via the seconds and display dates in undo lists but if I keep more than 50
events, it starts to get too slow to update! Array operations, not being
able to put array objects into array objects, etc... The subject goes far...


The real problem is that data doesn't follow the same growth curve as the
language's uses for it (the amount of data far outgrows computing power...)

However, often is the case when a list changes scales of sizes, the software
doesn't follow the same relative scales or exception entropy...
I guess this could be true of formats as well as their need of use... Sorry,
technical thoughts spoken outloud...

Sorry for the length, my free mind lunch on the subject hoping it will bring
better things for all in the future software we all rely on! I didn't mean
to downplay anyone, just saying that it could be better for all... Sorry if
I sounded angry before... 

Xav
--
http://MonsieurX.com/runrev.php 
Nitrous IDE tools - brakepads not necessary!





> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com 
> [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of 
> Rob Cozens
> Sent: Thursday, March 17, 2005 16:59
> To: How to use Revolution
> Subject: Re: check if an item is a date
> 
> This is nothing new, Xavier,
> 
> >But surprise!
> >
> >put (2485694 is a date)
> >
> >It gets worse... 1 is also a date!
> >
> >So either the << is a date>> function is useless as a date 
> checker and 
> >we all must roll our own AGAIN
> 
> Virtually any integer represents a date in seconds format in 
> xTalks; so if you need need to validate an input string as a 
> valid date (as per system date format), you need more:
> 
>  From Serendipity Library <http://wecode.org/serendipity/>:
> 
> function validDate theString -- 5 April 04:RCC
>    put stripBlanks(theString,false) into theString
>    get systemDateFormat()
>    set the itemDelimiter to char -1 of it -- theSeparator
>    if the number of items of theString <> 3 then return false
>    delete the last char of it
>    delete char offset("mm",it) of it -- remove double 
> characters, if any
>    delete char offset("dd",it) of it
>    delete char offset("yy",it) of it
>    repeat with x = 1 to 3
>      switch char x of it
>      case "m"
>        put item x of theString into theMonth
>        if not validDigits(theMonth) then return false
>        if theMonth < 1 or theMonth > 12 then return false
>        break
>      case "d"
>        put item x of theString into theDay
>        if not validDigits(theDay) then return false
>        if theDay < 1 or theDay > 31 then return false
>        break
>      case "y"
>        put item x of theString into theYear
>        if not validDigits(theYear) then return false
>        put length(theYear) into charCount
>        if charCount <> 2 and charCount <> 4 then return false
>        if charCount is 2 then add 2000 to theYear
>        if theYear < 1 then return false
>        break
>      end switch
>    end repeat
>    if theDay < 29 then return
> true&return&theYear&comma&theMonth&comma&theDay&",0,0,0,0"
>    if theMonth is 2 then
>      if theDay > 29 or not leapYear(theYear) then return false
>      else return 
> true&return&theYear&comma&theMonth&comma&theDay&",0,0,0,0"
>    else
>      if offset("0",theMonth) = 1 then delete char 1 of theMonth
>      set the itemDelimiter to comma
>      if theMonth is among the items of "1,3,5,7,8,10,12" then 
> return true&return&theYear&comma&theMonth&comma&theDay&",0,0,0,0"
>      if theDay is 31 then return false
>      else return 
> true&return&theYear&comma&theMonth&comma&theDay&",0,0,0,0"
>    end if
> end validDate
> 
> Note this uses the systemDateFormat function I posted 
> yesterday, plus other Library handlers.
> 
> Rob Cozens CCW
> Serendipity Software Company
> 
> "And I, which was two fooles, do so grow three;
>   Who are a little wise, the best fooles bee."
> 
>   from "The Triple Foole" by John Donne (1572-1631) 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 



More information about the use-livecode mailing list