Jump to content
water

Translate RFC 2445 duration format

Recommended Posts

For my iCal UDF I need to translate rfc 2445 duration format to an array holding the possible values (week, day, hour, minute, second):
Has anyone already written some code to to this?

Quote

4.3.6   Duration

   Value Name: DURATION

   Purpose: This value type is used to identify properties that contain a duration of time.

   Formal Definition: The value type is defined by the following notation:

     dur-value  = (["+"] / "-") "P" (dur-date / dur-time / dur-week)

     dur-date   = dur-day [dur-time]
     dur-time   = "T" (dur-hour / dur-minute / dur-second)
     dur-week   = 1*DIGIT "W"
     dur-hour   = 1*DIGIT "H" [dur-minute]
     dur-minute = 1*DIGIT "M" [dur-second]
     dur-second = 1*DIGIT "S"
     dur-day    = 1*DIGIT "D"

   Description: If the property permits, multiple "duration" values are specified by a COMMA character (US-ASCII decimal 44) separated list
   of values. The format is expressed as the [ISO 8601] basic format for the duration of time. The format can represent durations in terms of
   weeks, days, hours, minutes, and seconds.

   No additional content value encoding (i.e., BACKSLASH character encoding) are defined for this value type.

   Example: A duration of 15 days, 5 hours and 20 seconds would be:

     P15DT5H0M20S

   A duration of 7 weeks would be:

     P7W

"P15DT5H0M20S" should be translated to [0, 15, 5, 0, 20] ; week, day, hour, minute, second

Some RegExp guru around?
Any help is greatly appreciated :)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hmm. As I don't know which letters are mandatory in the expression and which expressions are allowed I'm not sure of the result... :sweating:
So here is a raw try. The returned array will always be 5 elements [ week, day, hour, minute, second ]

#Include <Array.au3>

$d = "P15DT5H0M20S"
;$d = "P7W"
;$d = "PT1H"
;$d = "P15DT30M"

$res = StringRegExp($d, 'P(?:(\d*)W)?(?:(\d*)D)?T?(?:(\d*)H)?(?:(\d*)M)?(?:(\d*)S?)', 3)
_ArrayDisplay($res)

 

Share this post


Link to post
Share on other sites

First, I'm amazed! (I tried this for a bit, but it was a bit too complicated for a newbie regex-er)

Second, I think the P is optional? I thought it referenced whether the value was positive or not... but I'm not sure

Third, can you explain what the difference between using a 3 flag and a 1 flag is? They seem to return the same thing :)


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Share this post


Link to post
Share on other sites

@mikell
Since seems that the P is mandatory, you can "capture" the other letters in order to know at which parameter is "assigned" the value previousely "captured" :)

@water
You could use something like this:

Func _RFC2445Conversion($strRawDuration)

    Local $arrResult, _    ; Array used to store the "capture(s)" from SRE
          $arrReturn[1][2] ; Array in which are stored "tidely" the various values, in the format Property|Value

    ; Store the result of the "capture(s)" in the array, which is going to be processed later
    $arrResult = StringRegExp($strRawDuration, "^(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$", $STR_REGEXPARRAYMATCH) ; [-+]?

    ;_ArrayDisplay($arrResult)

    ; Add the various "capture(s)" in the array that will be returned
    For $i = 0 To UBound($arrResult) - 1 Step 1
        If $arrResult[$i] <> 0 Then _ArrayAdd($arrReturn, StringRegExpReplace($arrResult[$i], "(\d+)([WDHMS])", "$2|$1"))
    Next

    ; This, or delete the first element of the array (which will always be blank)
    $arrReturn[0][0] = "Raw Duration"
    $arrReturn[0][1] = $strRawDuration

    Return $arrReturn

In case you have only one Duration:

Spoiler
#include <Array.au3>

Global $strDuration = "P15DT5H0M20S"

_ArrayDisplay(_RFC2445Conversion($strDuration))

 

In case you have multiple Durations, delimited by a comma:

Spoiler
#include <Array.au3>


Global $strDuration = "P15DT5H0M20S, P7W, PT1H, P15DT30M", _
       $arrDurations

$arrDurations = StringSplit($strDuration, ", ", $STR_ENTIRESPLIT)

For $i = 1 To $arrDurations[0] Step 1
    _ArrayDisplay(_RFC2445Conversion($arrDurations[$i]))
Next

 

If you could tell us what is the sign - or + used for, it can be inserted in the pattern in order to be "captured" as well :)

@seadoggie01
The difference between Flag 1 and 3 is that the first returns from the function after the first "match", and the second continues trying to "match" the pattern all over the rest of the string.
Something like this:

Spoiler
#include <Array.au3>


Global $strDuration = "P15DT5H0M20S"
_ArrayDisplay(StringRegExp($strDuration, "^(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$", $STR_REGEXPARRAYMATCH), "$STR_REGEXPARRAYMATCH")

Global $strDuration = "P15DT5H0M20S, P0DT1H2M3S"
_ArrayDisplay(StringRegExp($strDuration, "(?:P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)", $STR_REGEXPARRAYGLOBALMATCH), "$STR_REGEXPARRAYGLOBALMATCH")

 

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Here's my suggestion:

#include <Constants.au3>
#include <Array.au3>


_ArrayDisplay(rfc2445_duration("+P7W")        , "+P7W")
_ArrayDisplay(rfc2445_duration("+P7W5D")      , "+P7W5D")
_ArrayDisplay(rfc2445_duration("+P7W5D6H")    , "+P7W5D6H")
_ArrayDisplay(rfc2445_duration("+P7W5D6H2M")  , "+P7W5D6H2M")
_ArrayDisplay(rfc2445_duration("+P7W5D6H2M6S"), "+P7W5D6H2M6S")

Func rfc2445_duration($sRfc2445Duration)
    Enum $WEEK, $DAY, $HOUR, $MIN, $SEC

    Local $aDuration[5], _
          $aResult
    Local $iDuration = 0

    ;Get week
    $iDuration = 0
    $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)W", $STR_REGEXPARRAYMATCH)
    If IsArray($aResult) Then $iDuration = $aResult[0]
    $aDuration[$WEEK] = $iDuration

    ;Get day
    $iDuration = 0
    $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)D", $STR_REGEXPARRAYMATCH)
    If IsArray($aResult) Then $iDuration = $aResult[0]
    $aDuration[$DAY] = $iDuration

    ;Get hour
    $iDuration = 0
    $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)H", $STR_REGEXPARRAYMATCH)
    If IsArray($aResult) Then $iDuration = $aResult[0]
    $aDuration[$HOUR] = $iDuration

    ;Get min
    $iDuration = 0
    $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)M", $STR_REGEXPARRAYMATCH)
    If IsArray($aResult) Then $iDuration = $aResult[0]
    $aDuration[$MIN] = $iDuration

    ;Get secs
    $iDuration = 0
    $aResult = StringRegExp($sRfc2445Duration, "(?i)(\d+)S", $STR_REGEXPARRAYMATCH)
    If IsArray($aResult) Then $iDuration = $aResult[0]
    $aDuration[$SEC] = $iDuration

    Return $aDuration
EndFunc

 

Edited by TheXman

Share this post


Link to post
Share on other sites

Thanks a lot for your replies.
I will test as soon as I find some spare time.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@mikell

Quote

dur-value  = (["+"] / "-") "P" (dur-date / dur-time / dur-week)

I interpret "+" and "-" to be optional, "P" as mandatory.

I just tested your solution and it works great :thumbsup:
Thanks to all other users for their effort to help me solve my problem :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
On 17.1.2019 at 11:39 PM, FrancescoDiMuro said:

If you could tell us what is the sign - or + used for, it can be inserted in the pattern in order to be "captured" as well :)

The sign - or + is used to tell if the duration should be added (e.g. to calculate the end date-time of an event) or subtracted (e.g. when the alarm for an event should go off).
Now the result has 5 elements (for week, day, hour, minute and second).
I would be glad if you could modify the RegExp to add the +/- sign so we get (plus/minus, week, day, hour, minute and second).

Thanks a lot for your support!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water

^(?:([-+])?P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?)$

This RegEx returns an array of 6 elements, which are:

  • Plus/minus sign;
  • Week(s);
  • Day(s);
  • Hour(s);
  • Minute(s);
  • Second(s).

Each field is optional, except the P, which has always to be in the string in that exact position.

The RegEx could returns a more precise result if each field has ranges too (for example, Week parameter goes from 1 to N, and so on).

Try it, and let us know :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

It works using a slight variation of my previous expression - but will it be easier for you than a simple StringLeft($string, 1) ?

#Include <Array.au3>

;$d = "P15DT5H0M20S"
;$d = "P7W"
;$d = "+PT1H"
$d = "+P15DT30M"

$res = StringRegExp($d, '([+-]?)P(?:(\d*)W)?(?:(\d*)D)?T?(?:(\d*)H)?(?:(\d*)M)?(?:(\d*)S?)', 3)

_ArrayDisplay($res)

 

@FrancescoDiMuro

I guess that you didn't test your expression against the various possibilities I mentioned in my snippet  :)

Share this post


Link to post
Share on other sites

Thanks a lot for the updated expression!

15 minutes ago, mikell said:

but will it be easier for you than a simple StringLeft?

I fear it would take a lot of ordinary AutoIt code to split this string. Having a one line RegExp makes it fast and short :)
I will have a reference to this thread in the iCal UDF so that everyone knows who wrote it and how it works ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Quote

The RegEx could returns a more precise result if each field has ranges too (for example, Week parameter goes from 1 to N, and so on).

I assume that the ics file has a valid format so your regular expressions are exactly what I need :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@mikell
Try your pattern on this string and tell us what is returned:

+P15DT30

It will fail since you can't assume that the last \d* is effectively the S(Seconds(s)) parameter, and indeed it is "captured" as it is, even if it's not (it should be hours taking the order of the string).

@water
It depends from what do you want to manage: a 1-Dimensional array, a 2-Dimensional array, or a string in which you have Sign="", W="", D="15", and so on...

This function returns a string of what is being effectively "captured" from the string you pass to it, so, no pre-sized arrays are filled:

ConsoleWrite(_RFC2445Conversion("+P15DT5H0M20S") & @CRLF) ; Sign = +, D = 15, H = 5, M = 0, S = 20
ConsoleWrite(_RFC2445Conversion("+P7W") & @CRLF)          ; Sign = +, W = 7  
ConsoleWrite(_RFC2445Conversion("+PT1H") & @CRLF)         ; Sign = +, H = 1
ConsoleWrite(_RFC2445Conversion("+P15DT30M") & @CRLF)     ; Sign = +, D = 15, M = 30
ConsoleWrite(_RFC2445Conversion("-15DT30M") & @CRLF)      ; Doesn't return anything
ConsoleWrite(_RFC2445Conversion("+P15DT30") & @CRLF)      ; Doesn't return anything


Func _RFC2445Conversion($strRawDuration)

    Local $arrResult, _     ; Array used to store the "capture(s)" from SRE
          $strDuration = "" ; Variable used to return the Duration

    ; Store the result of the "capture(s)" in the array
    $arrResult = StringRegExp($strRawDuration, "^([-+])P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?$", $STR_REGEXPARRAYGLOBALMATCH)

    If IsArray($arrResult) Then
        $strDuration = "Sign = " & $arrResult[0] & ", "
        For $i = 1 To UBound($arrResult) - 1 Step 1
            If $arrResult[$i] <> "" Then
                If $i < UBound($arrResult) - 1 Then
                    $strDuration &= StringRight($arrResult[$i], 1) & " = " & StringRegExp($arrResult[$i], "^(\d+)(?:[WDHMS])$", 1)[0] & ", "
                Else
                    $strDuration &= StringRight($arrResult[$i], 1) & " = " & StringRegExp($arrResult[$i], "^(\d+)(?:[WDHMS])$", 1)[0]
                EndIf
            EndIf
        Next
    EndIf

    Return $strDuration

EndFunc

P.S.: Since you've said that the sign is used to add or subtract the time period, then it automatically became mandatory :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
5 minutes ago, FrancescoDiMuro said:
+P15DT30

It will fail since you can't assume that the last \d* is effectively the seconds, and indeed it is "captured" as seconds, even if it's not (it should be hours).

Right. I don't know the RFC 2445 format, so based on the syntax definition that water provided in post #1 I assumed that the letters are mandatory after each concerned number - so +P15DT30 could not be a valid RFC 2445 duration to be treated   :)

BTW this

StringRegExp("+PT1H", '^([-+])P(\d*W)?(\d*D)?T?(\d*H)?(\d*M)?(\d*S)?$', 3)

does not return a 6 elements array (required)

Share this post


Link to post
Share on other sites
2 minutes ago, mikell said:

(required)

Let's see what @water says :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

The RFC 5545 specification for the duration can be found here: https://tools.ietf.org/html/rfc5545#page-35
The formal grammar for the content type is based on the Internet ABNF defined in RFC 5234.

My understanding is:

  • + and - are optional
  • Letter "P" is mandatory
  • letters are mandatory after each concerned number
  • "1*DIGIT" in the specification stands for 1 or multiple digits

So "-15DT30M" should be "-P15DT30M" and "+P15DT30" should be "+P15DT30M".

Thanks a lot for your assistance!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water
The following script returns an array of six elements, ordered in this way:
Array element #0 = Sign;
Array element #1 = Week(s);
Array element #2 = Day(s);
Array element #3 = Hour(s);
Array element #4 = Minute(s);
Array element #5 = Second(s).

The script controls if the passed string has the format required by the RFC2445 specification, and then process it, extracting all the parameters as it is stated above.

#include <Array.au3>
#include <StringConstants.au3>

_ArrayDisplay(_RFC2445Conversion("+P15DT5H0M20S") , "+P15DT5H0M20S")
_ArrayDisplay(_RFC2445Conversion("P7W"), "+P7W")
_ArrayDisplay(_RFC2445Conversion("-PT1H"), "-PT1H")
_ArrayDisplay(_RFC2445Conversion("+P15DT30M"), "+P15DT30M")
_ArrayDisplay(_RFC2445Conversion("-15DT30M"), "-15DT30M")
_ArrayDisplay(_RFC2445Conversion("+P15DT30"), "+P15DT30")
_ArrayDisplay(_RFC2445Conversion("P1D15H"), "P1D15H")
_ArrayDisplay(_RFC2445Conversion("P25DT1H2M3S"), "P25DT1H2M3S")

Func _RFC2445Conversion($strRawDuration)

    Local $arrDuration[6], _
          $arrPatterns[6] = ["([-+])", _
                             "(?:(\d+)W)", _
                             "(?:(\d+)D)", _
                             "(?:(\d+)H)", _
                             "(?:(\d+)M)", _
                             "(?:(\d+)S)"], _
          $arrResult


    If StringRegExp($strRawDuration, "^([-+]?)P(?=\d+[WDHMS])(\d+W)?(\d+D)?(?:T)?(\d+H)?(\d+M)?(\d+S)?$", $STR_REGEXPMATCH) <> 0 Then
        For $i = 0 To UBound($arrPatterns) - 1 Step 1
            $arrResult = StringRegExp($strRawDuration, $arrPatterns[$i], $STR_REGEXPARRAYMATCH)
            If IsArray($arrResult) Then $arrDuration[$i] = $arrResult[0]
        Next
    Else
        Return SetError(1, 0, 0)
    EndIf

    Return $arrDuration

EndFunc

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

So the final version should obviously be

#Include <Array.au3>

;$d = "+P15DT5H0M20S"
;$d = "P7W"
$d = "+PT1M"
;$d = "+P15DT30M"

$res = StringRegExp($d, '(?x)^([-+]?) P(\d+W)?(\d+D)? (?:T(\d+H)?(\d+M)?(\d+S)?)? $', 3)
; maybe some error checking here...
Redim $res[6]
For $i = 1 to 5
   $res[$i] = Number($res[$i])
Next

_ArrayDisplay($res)

Please note that checking the validity was not initially included in the deal  :)

Edited by mikell

Share this post


Link to post
Share on other sites

@mikell

Only the string P is not a valid input, so, a positive lookahead should do the trick ^_^

^([-+]?)P(?=\d+[WDHMS])(\d+W)?(\d+D)?(?:T)?(\d+H)?(\d+M)?(\d+S)?$

@water

See this post (edited) :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Thanks guys for your efforts!

I'm not going to check the validity of the input file. Translating a valid ics file to Outlook is complex enough.
Validating the iCal file is a task for online/offline validators. Example: https://icalendar.org/validator.html

So I'm happy with a RegExp that simply splits the property :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By water
      Built on top of the OutlookEX UDF it offers some often needed extended functionality (import/export ics/vcf/csv files etc.) (former name: iCal UDF).
      Note: This is a beta version - script breaking changes may occur at any time!
      Prerequisite: OutlookEX UDF.
      Details about all functions can be found in the Wiki.
      ICS (iCalendar) import - Import iCal events from an ICS file to an Outlook calendar
      VCF (vCard) import - Import vCard contacts to an Outlook contacts folder
      CSV import - Import data from a CSV file and create Outlook items in a specified folder
      Export - Export Outlook items (contacts, appointments) in VCF, ICS, CSV or Excel format
       
      Links:
      https://tools.ietf.org/html/rfc5545 (ICS - iCalendar)
      https://tools.ietf.org/html/rfc6350 (VCF - vCard)
      Threads:
      General Help & Support
       
      Known Bugs: (last changed: 2019-01-22)
      None
        Things to come: (last changed: 2019-07-22)
      None
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • By water
      I just noticed that Outlook does not allow to import iCal events programmatically.
      I might implement some of the iCalendar data format (RFC 5545) if someone is interested
      Please post here or click the "Like" button if you think this is a good idea
      Edit: For download please see my signature
×
×
  • Create New...