[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath expression to extract the hour offset from

Subject: Re: XPath expression to extract the hour offset from strings that express time offset from UTC?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 Dec 2022 14:16:30 -0000
Re:  XPath expression to extract the hour offset from
On Tue, Dec 13, 2022 at 01:49:23PM -0000, Roger L Costello costello@xxxxxxxxx scripsit:
> Hi Folks,
> 
> I have strings that express time offset from UTC. Here are representative examples:
> 
> UTC+5
> UTC+1(+2DT)
> UTC-11
> UTC+4:30
> UTC+9:30(+10:30DT)
> 
> In areas where daylight savings time is observed, the daylight savings time is the part in parentheses.
> 
> Some offsets have both an hour and minute. The minute portion is after the colon.
> 
> I need to extract the hour offset. So for the above examples, I need to extract:
> 
> +5
> +1
> -11
> +4
> +9

let $egs := ('UTC+5','UTC+1(+2DT)','UTC-11','UTC+4:30','UTC+9:30(+10:30DT)')

for $each in $egs
  return
  (
  (((tokenize($each,'[()]')[2] => tokenize(':'))[1]) => replace('\p{L}',''))[normalize-space()],
  replace($each,'^UTC([+\-]\p{Nd}+).*$','$1')
) => head()

produces

+5
+2
-11
+4
+10

If you have lots of these or expect it  not to be a one-time thing, it
seems like the right thing to do would be to convert the odd format into
xs:time and then rely on the built in functions.


-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.