View script | License | Download documentation as: HTML or editable |
Download script | History | Other scripts by: chrisrg |
[0.078] 18.265k
Documentation for: form-date.rUsage document for %form-date.r1. Introduction to %form-date.rThis library script is for inclusion in other programs and allows sophisticated date formatting, ala strftime, but not exactly 2. form-date At a Glance>> form-date now "%A %e%i %B, %Y at %T" == "Thursday 26th April, 2007 at 00:44:12" >> form-date now "%d-%b-%Y/%H:%M:%S%Z" == "26-Apr-2007/00:49:39-04:00" >> now == 26-Apr-2007/0:52:13-4:00 >> form-date now/precise "%c" == "19-Jul-2007/00:01:45.108242-04:00" 3. Using %form-date.rIncluding this function is simple. Just DO it. >> do %form-date.r or to execute this right out of the rebol.org library >> do http://www.rebol.org/download-a-script.r?script-name=form-date.rYou now have the form-date function >> help form-date USAGE: FORM-DATE date format /gmt DESCRIPTION: Renders a date to a given format (largely compatible with strftime) FORM-DATE is a function value. ARGUMENTS: date -- (Type: date) format -- (Type: any-string) REFINEMENTS: /gmt -- Align time with GMT 4. The format stringOrdinary characters placed in the format string are inserted into return value without conversion. Conversion specifications are introduced by a % character, and terminated by a conversion specifier character, and are replaced and inserted into return value as follows:
5. What you can learnThe interpolate function, along with date-codes is an excellent example of parse. The dialect created is the two character format specifiers that produce the date and time pieces. A strftime dialect. REBOL can emulate the functionality of other systems, while still remaining REBOL. REBOL code can look world-class elegant when properly formatted and factored. 6. What you can breakThe date! parameter has to be a date!. If you use any time related format specifiers, it has to be a date! that includes time information or returned fields may be incorrect. >> form-date now/date "%T" == "00:00:00" >> form-date now/time "%T" Script Error: form-date expected date argument of type: date Near: form-date now/time "%T" >> form-date now "%T" == "02:29:39" 7. What's newWith the addition of %c, you have clean, always the same length REBOL time-stamps. >> 01-Jan-0001/00:00:00.000000-00:00 == 1-Jan-0001/0:00 >> form-date 01-Jan-0001/00:00:00.000000-00:00 "%c" == "01-Jan-0001/00:00:00.000000+00:00" >> form-date now/precise "%c" == "19-Jul-2007/00:42:53.586560-04:00" >> form-date now "%c" == "19-Jul-2007/00:43:19.000000-04:00" 7.1. Precision versus AccuracyPlease note that now/precise while reporting 6 digit precision for the sub-seconds, is only as accurate as your computer clock will allow. 8. Credits
|