Chor Wai Chun
Chor Wai Chun

Reputation: 3236

C# DateTime Format YYMMDDhhmmsstnnp

I'm currently using a third party DLL to run some of my programs.

It was working fine until recently I decided to move it to a new server running OS Windows Server 2016.

The library suddenly pops an error saying:

System.FormatException: Incorrect format. 'YYMMDDhhmmsstnnp'

I looked here https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings but couldn't see anything for t, nn and p.

Does anyone recognize the format above and knows what actually is t nn and p?

And how do I actually resolve the issue?

Thank you

Upvotes: 0

Views: 328

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

Okay, after a little detective work (well, a search) I believe you're probably using the SMPPClient library, and that the error comes from this line. It's not trying to use that as a format string - it's only reporting it (unhelpfully, IMO) as the expected format of the string.

It's actually checking it using this regex:

"^[0-9][0-9][0-1][0-9][0-3][0-9][0-2][0-9][0-5][0-9][0-5][0-9][0-9][0-4][0-9][\\+\\-R]$"

The SMPP v5 specification explains the formatting:

  • ‘YY’ last two digits of the year (00-99)
  • ‘MM’ month (01-12)
  • ‘DD’ day (01-31)
  • ‘hh’ hour (00-23)
  • ‘mm’ minute (00-59)
  • ‘ss’ second (00-59)
  • ‘t’ tenths of second (0-9)
  • ‘nn’ Time difference in quarter hours between local time (as expressed in the first 13 octets) and UTC (Universal Time Constant) time (00-48).
  • ‘p’:
    “+” Local time is in quarter hours advanced in relation to UTC time.
    “-” Local time is in quarter hours retarded in relation to UTC time. “R” Local time is relative to the current SMSC time.

This isn't something I'd expect a regular format string in .NET to handle.

I would suggest that your next steps should be:

  • Find out what value it was trying to parse (that could be tricky, I understand)
  • Work out where that value comes from (is it generated elsewhere in the code, possibly in your code, or is it data originating outside your system?)
  • Write a small program to just perform that regex on both the working machine and the problematic machine to work out whether the problem is that the regex behaviour has changed, or the data being parsed has changed

My guess is that some code somewhere is using regular DateTime formatting to create part of this string, and then tweaking it for the last part... and that on your new system, there are some locale changes that affect things. For example, even if you format with an explicit format, that will still use the calendar system of whatever culture it's using - if you're formatting to a non-Gregorian calendar accidentally, that could definitely affect things. (The common fix there is to explicitly use CultureInfo.InvariantCulture when formatting a machine-readable string.)

Upvotes: 2

Related Questions