Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

/precise problem

 [1/4] from: rchristiansen::pop::isdfa::sei-it::com at: 27-Dec-2000 15:49


I'm working on updating my time-in-digits.r script so that it can use the /precise refinement as provided in the /Core experimental. However, I am running into a bit of a problem. The thousandths-of-a-second are returned with either one, two, or three decimal places, as such... 27-Dec-2000/15:36:52.739-6:00 27-Dec-2000/15:36:52.75-6:00 27-Dec-2000/15:36:52.76-6:00 27-Dec-2000/15:36:52.77-6:00 27-Dec-2000/15:36:52.78-6:00 27-Dec-2000/15:36:52.79-6:00 27-Dec-2000/15:36:52.8-6:00 27-Dec-2000/15:36:52.81-6:00 REBOL does not consistently return three decimal places for thousandths-of-a-second (i.e. if the value is ".300" then it just returns .3 ) No problem, I created a workaround where current-time: now/time/precise seconds: to-string current-time/second split-seconds: parse/all seconds "." whole-seconds: first split-seconds partial-seconds: second split-seconds while [(length? whole-seconds) < 2][insert whole-seconds "0"] while [(length? partial-seconds) < 3][append partial-seconds "0"] This appears to work until the thousandths-of-a-second value reaches either 1,000 or zero (not sure how REBOL is handling this, which is where the problem lies, I believe.) Here is the output of my console in using my updated time-in-digits.r script with the following usage: forever [print time-in-digits now/precise] 20001227152414930 20001227152414930 20001227152414940 20001227152414940 20001227152414950 20001227152414950 20001227152414960 20001227152414960 20001227152414970 20001227152414970 20001227152414980 20001227152414980 20001227152414990 20001227152414990 ** Script Error: Out of range or past end ** Where: time-in-digits ** Near: partial-seconds: second split-seconds while [(length? whole-seconds) < 2] Any clue as to what might be going on? Is REBOL returning four decimal places when it reaches the next full second? Or is it returning a "none" value? I'm not sure how to debug this. The script follows. Thanks. -Ryan BTW: using 'help on 'now tells you the /precise refinement is returning "nanosecond precision." Wouldn't that be nine decimal places? REBOL [ Title: "Date and time in digits" Date: 27-Dec-2000 Name: 'time-in-digits Version: 1.1.0 File: %time-in-digits.r Author: "Ryan C. Christiansen" Email: [norsepower--uswest--net] Owner: "Ryan C. Christiansen" Rights: "Copyright (C) Ryan C. Christiansen 2000" Tabs: 4 Language: 'English Purpose: { Convert the date and time into a string of digits. } Comment: { Use this function to create a string of digits denoting the date and time. This is useful, especially with 'now to create a reference number as to when a file, object, etc., was created. If used with 'now to create a file name, the newest file will always appear at the end of a directory. } History: [ 1.0.0 [12-June-2000 "posted to rebol.com" "Ryan"] 1.1.0 [27-Dec-2000 "updated for /precise refinement" "Ryan"] ] Category: [util 2] ] time-in-digits: func [ "Convert the date and time from 'now' into a string of digits." sun-dial [date!] "The current date and time from 'now'" ][ year: to-string sun-dial/year month: to-string sun-dial/month if (length? month) < 2 [insert month "0"] day: to-string sun-dial/day if (length? day) < 2 [insert day "0"] current-time: sun-dial/time hour: to-string current-time/hour if (length? hour) < 2 [insert hour "0"] minutes: to-string current-time/minute if (length? minutes) < 2 [insert minutes "0"] seconds: to-string current-time/second split-seconds: parse/all seconds "." whole-seconds: first split-seconds partial-seconds: second split-seconds while [(length? whole-seconds) < 2][insert whole-seconds "0"] while [(length? partial-seconds) < 3][append partial-seconds "0"] rejoin [year month day hour minutes whole-seconds partial-seconds] ]

 [2/4] from: al:bri:xtra at: 28-Dec-2000 14:25


> This appears to work until the thousandths-of-a-second value reaches
either 1,000 or zero (not sure how REBOL is handling this, which is where the problem lies, I believe.) Probably goes from 999 and roll around to 0, or none.
> ** Script Error: Out of range or past end > ** Where: time-in-digits > ** Near: partial-seconds: second split-seconds > while [(length? whole-seconds) < 2]
Probably 'whole-seconds is 'none ? I hope that helps! Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [3/4] from: rchristiansen:pop:isdfa:sei-it at: 28-Dec-2000 14:48


OK. It appears the /precise refinement when it rolls the thousandths- of-a-second from 999 back to 0 that it does NOT return zero nor none but some other value.
> > This appears to work until the thousandths-of-a-second value reaches > either 1,000 or zero (not sure how REBOL is handling this, which is where
<<quoted lines omitted: 5>>
> > while [(length? whole-seconds) < 2] > Probably 'whole-seconds is 'none ?
20001228143859967 20001228143859977 20001228143859987 20001228143859987 20001228143859997 ** Script Error: Out of range or past end ** Where: time-in-digits ** Near: partial-seconds: second split-seconds
>> print split-seconds
7E-3
>>
Please forgive my ignorance, but what does the 7E-3 notation stand for in mathematical terms? (I haven't had a math class since high school.) And why is this value showing up? The word 'split-seconds is supposed to return two items in a series, both of which are string! datatypes. My new time-in-digits function follows. It includes some error checking in an attempt to harness the /precise refinement. Thanks -Ryan time-in-digits: func [ "Convert the date and time from 'now' into a string of digits." sun-dial [date!] "The current date and time from 'now'" ][ year: to-string sun-dial/year month: to-string sun-dial/month if (length? month) < 2 [insert month "0"] day: to-string sun-dial/day if (length? day) < 2 [insert day "0"] current-time: sun-dial/time hour: to-string current-time/hour if (length? hour) < 2 [insert hour "0"] minutes: to-string current-time/minute if (length? minutes) < 2 [insert minutes "0"] seconds: to-string current-time/second seconds-rounded: make integer! current-time/second either current-time/second = seconds-rounded [ whole-seconds: seconds partial-seconds: "000" ][ split-seconds: parse/all seconds "." whole-seconds: first split-seconds partial-seconds: second split-seconds ] while [(length? whole-seconds) < 2][insert whole-seconds "0"] while [(length? partial-seconds) < 3][append partial-seconds "0"] rejoin [year month day hour minutes whole-seconds partial-seconds] ]

 [4/4] from: lmecir:mbox:vol:cz at: 28-Dec-2000 23:21


Hi Ryan, your problem was, that you were searching for ".", while "." might not have been there... 7E-3 is the same as 0.007, as you can see from: same? 7e-3 0.007 ; == true Regards Ladislav ----- Original Message ----- From: Ryan C. Christiansen <[RChristiansen--pop--isdfa--sei-it--com]> To: Andrew Martin <[Al--Bri--xtra--co--nz]> Cc: <[rebol-list--rebol--com]>

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted