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

[REBOL] /precise problem

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] ]