Documention for: form-date.r Created by: btiffin on: 27-Apr-2007 Last updated by: chrisrg on: 19-Feb-2009 Format: text/editable Downloaded on: 19-Apr-2024 [h1 Usage document for %form-date.r [contents [numbering-on [h2 Introduction to %form-date.r [p This library script is for inclusion in other programs and allows sophisticated date formatting, ala strftime, but not exactly [h2 form-date At a Glance [asis >> 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" asis] [h2 Using %form-date.r [p Including this function is simple. Just <strong>DO</strong> it. [asis >> do %form-date.r asis] [p or to execute this right out of the rebol.org library [asis/style/font-size:75% >> do http://www.rebol.org/download-a-script.r?script-name=form-date.r asis] You now have the form-date function [asis >> 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 asis] [h2 The format string [p Ordinary characters placed in the format string are inserted into return value without conversion. Conversion specifications are introduced by a <strong>%</strong> character, and terminated by a conversion specifier character, and are replaced and inserted into return value as follows: [table/att/border="1" [row [cell **%a** [cell The abbreviated weekday name according to the current locale. [row [cell **%A** [cell The full weekday name according to the current locale. [row [cell **%b** [cell The abbreviated month name according to the current locale. [row [cell **%B** [cell The full month name according to the current locale. [row [cell **%c** [cell The preferred date and time representation for the current locale. In this case the **locale** is REBOLand, with a little %b mixed in. [row [cell **%C** [cell The century number (year/100) as a 2-digit integer. [row [cell **%d** [cell The day of the month as a decimal number (range 01 to 31). [row [cell **%D** [cell Equivalent to %Y/%m/%d. [row [cell **%e** [cell Like %d, the day of the month as a decimal number, without a leading zero. [row [cell **%G** [cell The ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead. [row [cell **%g** [cell Like %G, but without century, i.e., with a 2-digit year (00-99). [row [cell **%H** [cell The hour as a decimal number using a 24-hour clock (range 00 to 23). [row [cell **%i** [cell The english suffix for numeric value, "st" for 01, "th" for 04. [row [cell **%I** [cell The hour as a decimal number using a 12-hour clock (range 01 to 12). [row [cell **%j** [cell The day of the year as a decimal number (range 001 to 366). [row [cell **%J** [cell Like %j, but without leading zeroes. [row [cell **%m** [cell The month as a decimal number (range 01 to 12). [row [cell **%M** [cell The minute as a decimal number (range 00 to 59). [row [cell **%p** [cell Either ""AM"" or ""PM"" according to the given time value. Noon is treated as ""PM" and midnight as ""AM". [row [cell **%s** [cell The second as a decimal number 00-60 with REBOL nanosecond precision, a period followed by 6 digits. [row [cell **%S** [cell The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.) [row [cell **%t** [cell A tab character. [row [cell **%T** [cell The time in 24-hour notation (%H:%M:%S). [row [cell **%u** [cell The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w. [row [cell **%U** [cell The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W. [row [cell **%V** [cell The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. See also %U and %W. [row [cell **%w** [cell The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u. [row [cell **%W** [cell The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01. [row [cell **%y** [cell The year as a decimal number without a century (range 00 to 99). [row [cell **%Y** [cell The year as a decimal number including the century. [row [cell **%Z** [cell The time-zone as hour offset from GMT. [row [cell **%%** [cell A literal ""%"" character. table] [h2 What you can learn [p The <strong>interpolate</strong> function, along with <strong>date-codes</strong> is an excellent example of <strong>parse</strong>. The dialect created is the two character format specifiers that produce the date and time pieces. A strftime dialect. [p REBOL can emulate the functionality of other systems, while still remaining REBOL. [p REBOL code can look world-class elegant when properly formatted and factored. [h2 What you can break [p The 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. [asis >> 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" asis] [h2 What's new [p With the addition of %c, you have clean, always the same length REBOL time-stamps. [asis >> 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" asis] [h3 Precision versus Accuracy [p Please note that **now/precise** while reporting 6 digit **precision** for the sub-seconds, is only as **accurate** as your computer clock will allow. [h2 Credits [li %form-date.r original author: Christopher Ross-Gill [li Part of QuarterMaster, %qm.r by Christopher Ross-Gill http://www.ross-gill.com/ [li Usage document by Brian Tiffin, Library Team Apprentice, [date