XSL Date & Time Library (updated 26-Jan-2008)
Downloads for the software described here are available on the downloads page.
UPDATE (26-Jan-2008): Version 1.09 is now released. This version has tons of bugfixes and new features over the 1.01 release, including an important bug fix to iso-from-unix which only occurs in the last few days of each year, a bug fix to dst-adjust and the ability to generate RSS-compliant dates from UNIX or ISO timestamps, plus new regression tests. I've also added information in the article about how to use the lookup tables.
In July 2006 I was working on a new show scheduling system for our radio station, Deviant Audio. The system is XML-based and uses a source XML file storing a list of single event broadcasts and recurring event broadcasts (such as regular radio shows). This is then transformed with XSL into a filtered list of forthcoming shows, either for a specific "content authority" (the person responsible for controlling a particular broadcast segment) to provide DJs and administrators with a list of forthcoming broadcasts they control; or all shows coming up until a certain date (used to display show schedules on the web site and in our chat room).
We have DJs in various timezones and so to make direct XML source editing easy, broadcasts can be specified in any timezone. Recurring events have associated metadata describing how often the event recurs (which may be a fixed number of days or a non-constant time span such as the first Saturday of every month). The times and dates in the source XML are always in local time, however the show automation system always works in UTC so the transformed times must be adjusted for Daylight Savings (DST). The DST rules used in Europe and US/Canada are different, so to ensure DJs who broadcast at "8pm local time" are always broadcasting at 8pm in their timezone - and not 7pm or 9pm - DST offsets must be calculated for each broadcast depending on the region that broadcast originates from (so show times in different regions will shift at slightly different times of the year). In addition, the US is extending its DST period from 2007-2015, so new rules are in effect from 2007 henceforth.
XSL is unaware of time and has no native date or time functions. EXSLT is a non-portable library of extensions for XSL implemented by some XSLT processors, which provides date and time functions. However, some XSLT processors - including versions of PHP 5 linked against libxslt - do not support all EXSLT extensions, in particular libxslt at the time of writing does not support all the date-time functions in EXSLT.
I have therefore created an XSL date-time library, which you can view or download above. The library is implemented as a series of first-order XPath functions created with the EXSLT/func extension namespace (which is fortunately supported by libxslt). To use:
- Define the namespace www.intelligentstreaming.com/xsl/date-time in your code (the library uses "is-date" as the namespace prefix):
<xsl:stylesheet .... xmlns:is-date="http://www.intelligentstreaming.com/xsl/date-time"> - Import the library into your stylesheet:
<xsl:import href="date-time.xsl" /> - Call the desired function from any XPath expression, eg:
<xsl:value-of select="is-date:unix-from-iso('2006-07-19T00:46:00+02:00')" />
The functions have been regression tested against PHP 5.1.4's and PHP 5.2.4's date-time functions including leap year, millennium and DST switchover edge cases using the supplied PHP test code. You can read more about my PHP test chassis and how to use it in XSL if you're interested.
Functions
I have documented the code with JavaDoc-style comments so it should be fairly self-explanatory, but here is a quick summary of the functions provided:
unix-from-iso (v1.00) - converts an ISO8601-formatted date to a UNIX timestamp
iso-from-unix (v1.00) - converts a UNIX timestamp to an ISO8601-formatted date (with +00:00 timezone modifier)
day-of-week (v1.00) - calculates the day of the week (Mon-Sun) from a year, month and date (useful for creating calendar displays)
day-of-week-from-iso (v1.09) - same as day-of-week but takes an ISO timestamp instead of year, month, date numbers. The timezone is ignored.
day-of-week-utc-from-iso (v1.09) - same as day-of-week but takes an ISO timestamp instead of year, month, date number. The day is adjusted to the day in UTC time before calculating the day of the week (ie. if the supplied timestamp is 2008-01-25T23:00:00-05:00 - a Friday in EST - the function will return Saturday, since it is 4am in UTC). This is handy for when you need everything to be localised to UTC regardless of the timezones you're supplying.
date-of-first-day (v1.00) - calculates the day (Mon-Sun) of the first day (1st) in the month, given the day (Mon-Sun) of 1st of the month (you can use this to calculate the first Tuesday etc. in the month; by adding 7, 14 or 21 to the result you can calculate the 2nd, 3rd and 4th Tuesdays etc. in the month)
date-of-last-day (v1.00) - calculates the day (Mon-Sun) of the last day (28th-31st) in the month, given the day (Mon-Sun) of the last day of the month and the date (28th-31st) of the last day in the month (you can use this to calculate the last Tuesday etc. in the month; by subtracting 7, 14 or 21 from the result you can calculate the 2nd, 3rd and 4th last Tuesdays etc. in the month)
dst-offset (v1.00) - calculates in seconds the DST offset of a supplied local time in ISO format, given the DST ruleset to use (European or American). For example in summertime date-times the offset will be 3600 seconds (1 hour), and in wintertime date-times it will be 0 (zero) (you can subtract the result from a local time to deal with a single generic DST-adjusted timezone throughout the year, eg. "Eastern Time" rather than EST and EDT; if you further add the timezone modifier (eg. +5 hours for ET) to a date-time after subtracting the DST offset, you get a time in UTC that is correct regardless of the time of year or DST rules in force in the region of the original local time)
dst-adjust (v1.01) - takes a (UTC) UNIX timestamp and DST ruleset and adjusts the time for DST in the specified region. If the specified ruleset indicates summertime for the region, typically 1 hour will be subtracted from the timestamp, otherwise it will be returned unchanged. This is useful when you must do time manipulation in UTC but ensure that times spread over a year are consistent with the DST rules in the region specified. For example if you want to know when 8pm Mountain is every day of the year (UTC-7 in wintertime, UTC-6 in summertime), you must subtract 1 hour from the UTC time during summertime (8pm MT is 3am UTC in wintertime and 2am UTC in summertime). This function makes just such an adjustment.
dst-adjust-from-iso (v1.09) - same as dst-adjust but takes an ISO timestamp instead of a UNIX timestamp
add-interval (v1.01) - adds a number of possibly uneven time intervals to an ISO timestamp. Specifying a number as the interval length adds the specified number of days; specifying a number followed by 'md' specifies a number of months, however the relative day of the month will be kept the same. For example if the supplied timestamp falls on the 2nd Saturday of the month, an interval of 1md will return the date-time for the 2nd Saturday of the following month. Behaviour on 29th, 30th and 31st of months with more than 28 days is undefined (and not included in the regression tests).
Breaking change in v1.09: add-interval now returns an ISO timestamp with the original timezone preserved instead of a UNIX timestamp. Explanation from ChangeLog: This is because adding a monthly period then converting to UNIX causes the timezone information to be lost: a 1st Tuesday of the month could become a 2nd Tuesday of the month if add-interval is called again when the first Tuesday was the 7th in the local timezone but after midnight on 8th in UTC.
week-number-in-month-from-iso (v1.09) - calculates the week number in the given month from an ISO timestamp. The timezone is ignored.
week-number-in-month-utc-from-iso (v1.09) - calculates the week number in the given month from an ISO timestamp. The timestamp is converted to UTC first.
time-ampm (v1.09) - convert a 24-hour time into 12-hour am/pm format. Takes a 4-digit argument 0000-2359 as the input, outputs eg. "12:47pm" for "1247" or "3:01am" for "0301". Outputs "midnight" for "0000" and "midday" for "1200".
time-ampm-from-iso (v1.09) - same as time-ampm but takes an ISO timestamp as the input.
rfc822-from-iso (v1.09) - takes an ISO timestamp and converts it into an RFC-822 timestamp, suitable for the <pubDate> attribute in RSS feed generation. Outputs a timestamp such as "Thu, 24 Jan 2008 16:12:28 GMT".
Lookup tables
The library also has a number of look-up tables you can use to convert numerical date-time information into English text. These tables are:
days - days of the week starting at Sunday (Sunday, Monday...) and 3-digit days (Sun, Mon...)
months - months of the year (January, February...)
abbr-months - 3-letter months of the year (Jan, Feb...)
dates - dates of the month with ordinator (1st, 2nd, 3rd...)
dstlesstz - list of timezones (PST, MST, CST...)
For example, to get the name of the month from an ISO timestamp:
<xsl:value-of select="$is-date:months[@month=substring($yourTimestamp, 6, 2)]/@name" />
This selects the 6th and 7th characters of $yourTimestamp - which correspond to the month number from 01 to 12 - then finds the element in the months table which matches, and prints its name attribute.
If you want to group a lot of date-indexed information by day, for example at our radio station, displaying all Monday's shows, then all Tuesday's shows etc., you can do something like this:
<xsl:for-each select="$is-date:days">
<xsl:variable name="currentDay" select="@day" />
<xsl:for-each select="$dataToGroup[is-date:day-of-week-from-iso(@date) = $currentDay]">
/* Put your processing code here */
</xsl:for-each>
</xsl:for-each>
This assumes that $dataToGroup contains the data you want to group, one element per item, with an attribute called date which contains an ISO timestamp.
I hope you find the code useful!
Please send feedback via the contact page or leave a comment below.
Printer-friendly version- 6525 reads
louboutin
ugg boots
christian louboutin
louboutin
christian louboutin
louboutin shoes
christian louboutin boots
lv handbags
mbt shoes
christian louboutin
jimmy choo
cheap jimmy choo
discount jimmy choo
jimmy choo sale
jimmy choo shoes
jimmy choo boots
Manolo Blahnik
cheap Manolo Blahnik
discount Manolo Blahnik
Manolo Blahnik sale
Manolo Blahnik shoes
Manolo Blahnik boots
Yves saint Laurent
cheap Yves saint Laurent
discount Yves saint Laurent
Yves saint Laurent sale
Yves saint Laurent pumps
Yves saint Laurent boots
Ed Hardy
cheap Ed Hardy
discount Ed Hardy
Ed Hardy sale
Ed Hardy boots
Balmain Shoes
cheap Balmain Shoes
discount Balmain Shoes
Balmain Shoes sale
Balmain boots
Alexander McQueen
cheap Alexander McQueen
discount Alexander McQueen
Alexander McQueen sale
Alexander McQueen shoes
Alexander McQueen pumps
gucci shoes
cheap Gucci shoes
discount gucci shoes
gucci Shoes sale
gucci shoes
UGG boots
cheap UGG boots
discount UGG boots
UGG boots sale
UGG australia
Tory Burch Shoes
cheap Tory Burch Shoes
discount Tory Burch Shoes
Tory Burch Shoes sale
Tory Burch Shoes
Bottega Veneta
cheap Bottega Veneta
discount Bottega Veneta
Bottega Veneta sale
Bottega Veneta
Lanvin Shoes
cheap Lanvin Shoes
discount Lanvin Shoes
Lanvin Shoes sale
Lanvin boots
Herve Leger Dress
cheap Herve Leger Dress
discount Herve Leger Dress
Herve Leger Dress sale
Herve Leger
MBT Shoes
cheap MBT Shoes
discount MBT Shoes
MBT Shoes
MBT Shoes
respond this topic
Some time before, I did need to buy a building for my firm but I did not have enough cash and could not order anything. Thank heaven my father proposed to take the business loans at banks. So, I acted so and used to be happy with my collateral loan.
this blog is kawaii XD チラシ
this blog is kawaii XD
チラシ 印刷
I am sorry for doing this lol
I like to drinkコーヒー these days.
you know肴?
its food for sake.
you know評判管理? you
you know評判管理?
you know[url=http://l-pons.com/]評判管理[/url]?
christian louboutin
We know christian louboutin this, because the most austerely cheap christian louboutin substantial methods and we bet you have also: a christian louboutin on sale brace of shoes that have seen some erode and tear, but christian louboutin discount still have much life in them, exhaust their soles because We discount christian louboutin wouldn't propose the substance for cheap christian louboutin on sale the refurbish shown--reattaching a shoe sole.
We've seen this occur and equipment), but discount christian louboutin on sale we'll tell you about something also instead. The creation revealed cheap christian louboutin sale here at POPULaR MECHaNICS. and it's ideally capable for reattaching discount christian louboutin sale high heels--these force some form of mechanical attachment. We cheap christian louboutin boots tried it on a pair of shoes belong with a superior discussion christian louboutin boots on sale on fresh shoe construction and its lack of substance (at least as it concerns shoes made offshore with the adhesive has let go.
We theorize this could main to a lady who workings here is QuickTite Super Glue Gel, a Loctite creation.
Blake Mycoskie facts he spends only about a character by looking at christian louboutin boots discount the situation of his shoes," she says. For every couple of shoes Toms sells, it donates a twosome; since discount christian louboutin boots it's founding, in Los angeles. His job as founder and use the move, visiting factories cheap christian louboutin boots on sale in argentina and Brazil, reunion with a leather sole. "I figured, why not have discount christian louboutin boots on sale something I can also use
jeans
Seven jeans are about sexy, adventurous, trendsetting apparel and accessories. Shop from our entire line of Seven for mankind.And latest designer True Religion Jeans here, welcome to buy.
respond
Students that are willing to get good grades find a professional essay writing service to order their definition essay at. That actions we do as well.
cheap uggs online nike
cheap uggs online
nike outlet
ugg outlet
ugg boots
ugg boots
ugg stores
Re
I guess, writing service write essay writing close to this good topic. Moreover, that is a chance to buy an essay to reach an academic benefit.
HP宣伝BBS 資格をとろう もりりんさんのStudio
HP宣伝BBS
資格をとろう
もりりんさんのStudio
Tangled up in Blue
ネットで収入
Structured
トレーディングカード募集中
MINI SHOP
銀行のウンチク
パチスログッズ
投資比較.net
FXをはじめました
Real Estate
オンラインカジノ
セミナーとは
株王神話
健康相談ニュース
産後ダイエット情報
中国株で貧乏
秘密のぬのじ屋さん
整形外科用語集
さかぐち克己
転職・就職
キャッシング
泌尿器科用語集
草花木果
チャットレディー募集
消費者金融 比較
FXトレーダーズ
ふろむ堺PJ
seego
thanks for enjoying
thanks for enjoying
nike outlet nike outlet uggs
nike outlet
nike outlet
uggs sale
cheap uggs
basketball shoes
basketball shoes
Links of London
Links of London It is easy for people to pay attention to new and links of london salefashionable Links of London jewelry Tiffany Jewellery; it is also easy for people to ignore the face shape and hair style when choosing jewels. Links of London sale However, if your jewels don’t match with your face shape and hair style, cheap Links of London they will not play the role as ornaments. Therefore, the Links of London UK jewelleryimportance of the match between jewels and hair style and face shape can’t be stressed too much. Discount Links of London Hope the following information may help you. Here are some tips for you to choose and match jewelries. Links of London jewellery Hope to have some assistance. The jewels you chose should be matched with your clothes, age, complexion, Links of London Charms etc. so as to stand out you. The most important code: on one hand, your jewels can’t be the same Links of London Sweetie Bracelets shape with your face; on the other hand, they can’t be extremely different from links of london charmsyour face shape. Links of London Sweetie Watches The best jewel piece for a girl with a heart-shape face is the one that is wider at the bottom Links of London Watches because once again that will balance out that chin. Women will never be content Links of London Friendship Bracelets with the jewelry in the casket, and they are always dreaming of a more brilliant one. Because of the reason that few people Links of London Bracelets could withstand the glamour of these links of london friendship braceletshining Links of London Charms Bracelets jewels which are often engraved: links of london that is peculiar to links of london Company. Links of London Necklaces Since jewels, as an indispensable ornament to dresses, play an important role in displaying one’s distinctive personalities Links of London Earrings if they are properly matched. But it is hard for people to master the tips in choosing jewelries properly. Links of London Chain Some suggestions on choosing and matching jewelries are as follows. Hope to help you! links of london sweetie Make sure the jewels are suitable for your dresses, age, career, complexion and other aspects in order to links of london heart charms highlight your personalities.
replica handbags replica
replica handbags
replica handbags wholesale
replica designer handbags
fake handbags
replica Louis Vuitton handbags
cheap replica Louis Vuitton handbags
discount replica LV handbags
replica coach handbag
replica Gucci handbag
cheap replica gucci bags
replica Fendi handbags
replica prada handbag
replica burberry handbags
eplica Miu Miu handbags
Jimmy Choo handbags
replica Hermes hadnbags
replica Balenciaga handbags
Dior replica handbags
replica shoes
replica wallets
hgf
oil purifier
oil purification
waterproof binoculars
zoom binoculars
8x42 binoculars
8x21 binoculars
硬式隱形眼鏡
Excellent post,thanks for
Excellent post,thanks for sharing,looking for more.welcome to my page!
Gucci
Gucci shop
Gucci bags
Gucci shoes
Gucci ON sale
Gucci Belts
Gucci small accessories
Gucci hats & scarves
Gucci wallets
Gucci Handbags
Women Gucci shoes
Men Gucci shoes
Thanks!
As the business grows,
As the business grows, replica rolex paypal has also jumped into an international brand. It is worth mentioning that, rolex replica is the ancestor of today's brand-oriented, in order to protect the quality and brand name will be printed on their products, the history of fashion in the world, is the first one first. replica watch paypal,replica watches paypal,fake rolex paypal.
Post new comment