Subject: Re: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath expression to extra, Martin Honnen martin | Thread | Re: [xsl] XPath expression to extra, David Carlisle d.p.c |
Re: [xsl] XPath expression to extra, Martin Honnen martin | Date | Re: [xsl] XPath expression to extra, David Carlisle d.p.c |
Month |