Skip to content

Commit

Permalink
Util: Factor out splitting of ISO9660 timestamp into components
Browse files Browse the repository at this point in the history
- in function ParseISO8601TimeStampToComponents
- no functional change
  • Loading branch information
MichaelHuth committed Sep 5, 2023
1 parent e33fa66 commit 50eef3f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2668,16 +2668,14 @@ threadsafe Function ParseISO8601TimeStamp(timestamp)
string timestamp

string year, month, day, hour, minute, second, regexp, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute
variable secondsSinceEpoch, timeOffset
variable secondsSinceEpoch, timeOffset, err

if(IsEmpty(timestamp))
return NaN
endif

regexp = "^([[:digit:]]+)-([[:digit:]]+)-([[:digit:]]+)[T ]{1}([[:digit:]]+):([[:digit:]]+)(?::([[:digit:]]+)([.,][[:digit:]]+)?)?(?:Z|([\+-])([[:digit:]]{2})(?::?([[:digit:]]{2}))?)?$"
SplitString/E=regexp timestamp, year, month, day, hour, minute, second, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute

if(V_flag < 5)
[err, year, month, day, hour, minute, second, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute] = ParseISO8601TimeStampToComponents(timestamp)
if(err)
return NaN
endif

Expand Down Expand Up @@ -2709,6 +2707,22 @@ threadsafe Function ParseISO8601TimeStamp(timestamp)
return secondsSinceEpoch
End

/// @brief Parses a ISO8601 timestamp to its components, year, month, day, hour, minute are required and the remaining components are optional and can be returned as empty strings.
///
threadsafe Function [variable err, string year, string month, string day, string hour, string minute, string second, string fracSeconds, string tzOffsetSign, string tzOffsetHour, string tzOffsetMinute] ParseISO8601TimeStampToComponents(string timestamp)

string regexp

regexp = "^([[:digit:]]+)-([[:digit:]]+)-([[:digit:]]+)[T ]{1}([[:digit:]]+):([[:digit:]]+)(?::([[:digit:]]+)([.,][[:digit:]]+)?)?(?:Z|([\+-])([[:digit:]]{2})(?::?([[:digit:]]{2}))?)?$"
SplitString/E=regexp timestamp, year, month, day, hour, minute, second, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute

if(V_flag < 5)
return [1, year, month, day, hour, minute, second, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute]
endif

return [0, year, month, day, hour, minute, second, fracSeconds, tzOffsetSign, tzOffsetHour, tzOffsetMinute]
End

/// @brief Return the disc folder name where the XOPs are located
///
/// Distinguishes between i386 and x64 Igor versions
Expand Down

0 comments on commit 50eef3f

Please sign in to comment.