Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Day Profile Action Item Add Error (String Is Not Recognized As Valid DateTime Value)

Day profile action item add error (String is not recognized as valid DateTime value)

By andre538, 16 June, 2025
Forums
DLMSDirector

Hello Mikko,

There is a a small bug in recent Director functionality, though I can't recognize is it a code problem or a directive trouble (#if !NET5_0_OR_GREATER || WINDOWS_UWP)

I'm working with Activity Calendar object, Passive calendar tab, Day profile tab.
While trying to add day profile action with a start time field "00:00:00", I'v got a message that string is not recongized as a valid DateTime Value.

I checked same action in quite an old Director version (may be 6 months old, let's name it "old source") - no problem, so i just made a little comparative debug.

"old source" of GxDateTime.cs (first "if" branch executed at my PC, so str = "M/d/yyyy HH:mm:ss";) ( private static string GetDateTimeFormat(CultureInfo culture))

#if !NET5_0_OR_GREATER || WINDOWS_UWP
str = "M/d/yyyy HH:mm:ss";
#else
str = culture.DateTimeFormat.ShortDatePattern + " " + culture.DateTimeFormat.LongTimePattern;
#if !WINDOWS_UWP

"new source" of GxDateTime.cs (no branch, just read culture) ( private static string GetDateTimeFormat(CultureInfo culture)):

string str = culture.DateTimeFormat.ShortDatePattern + " " + culture.DateTimeFormat.LongTimePattern;

"old version" of GxDateTime.cs (mine executable branch is string timeSeparator = ":"; string dateSeparator = "/"; )

private void Remove(StringBuilder format, CultureInfo culture)
{
#if !NET5_0_OR_GREATER || WINDOWS_UWP
string timeSeparator = ":";
string dateSeparator = "/";
#else
string timeSeparator = culture.DateTimeFormat.TimeSeparator;
string dateSeparator = culture.DateTimeFormat.DateSeparator;
#endif //!WINDOWS_UWP

"new version" of GxDateTime.cs (mine executable branch is string string timeSeparator = ":"; string dateSeparator = "/";)

private void Remove(StringBuilder format, CultureInfo culture)
{
#if !NET5_0_OR_GREATER || WINDOWS_UWP
string timeSeparator = ":";
string dateSeparator = "/";
#else
string timeSeparator = culture.DateTimeFormat.TimeSeparator;
string dateSeparator = culture.DateTimeFormat.DateSeparator;
#endif //!WINDOWS_UWP

So, in "old version" used date separator always "/", though it is differ from culture settings, it works ok.

In "new version " used date separator is read from culture in private static string GetDateTimeFormat(CultureInfo culture), and still uses "/" in Remove, so this results to a bug, because my system date separator (from culture) (".") is not removed from string.

Best regards, Andrew

Profile picture for user Kurumi

Kurumi

3 weeks 3 days ago

Hi Andrew, If you add the…

Hi Andrew,

If you add the start time, the date-separator is not used.

You didn't tell what .Net version and language you are using, but the time separator can also be in format 00.00.00.

The correct date and time formats depend on the localization settings used.

Check first is your using 00.00.00 or 00:00:00 format.

BR,
Mikko

andre538

3 weeks 3 days ago

Hi Mikko, as written in…

Hi Mikko,

as written in Visual Studio "About" dialog, I'm using "Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.12.3", Microsoft .NET Framework version 4.8.04084

As for "If you add the start time, the date-separator is not used":

- just after entering "00:00:00" in "start time" field (yes, I have 00:00:00 format ) we are dropping to public GXDateTime(string value, CultureInfo culture) with value="00:00:00", this step is ok

- in format.Append(GetDateTimeFormat(culture)); result format is "{dd.MM.yyyy H:mm:ssdd.MM.yyyy H:mm:ss}", this step is ok

- after that we drops to private void Remove(StringBuilder format, CultureInfo culture)

string dateSeparator = "/"; (this step is not ok)

- next steps
else if (this is GXTime)
{
Remove(format, "yyyy", dateSeparator);
Remove(format, "yy", dateSeparator);
Remove(format, "MM", dateSeparator);
Remove(format, "M", dateSeparator);
Remove(format, "dd", dateSeparator);
Remove(format, "d", dateSeparator);

each one is using dateSeparator as "/"
so resulting "fromat " value is "{.. H:mm:ss.. H:mm:ss}" (dd, mm, YYYY removed, "." date separators readed from culture are not removed) - this is wrong

and the final problem i at line

Value = DateTime.ParseExact(v, format.ToString(), culture); (of public GXDateTime(string value, CultureInfo culture))
here v is "00:00:00"
format is "{.. H:mm:ss.. H:mm:ss}" ("." date separators not removed, incorrect)

so at DateTime.ParseExact I'be got an exception

Profile picture for user Kurumi

Kurumi

3 weeks 2 days ago

Hello Andrew, This problem…

Hello Andrew,

This problem can't be repeated. Are you using am or pm? If you do, then you need to add it also. Like this: "12:00:00 am".

BR,
Mikko

andre538

3 weeks 2 days ago

Hello Mikko, to reproduce a…

Hello Mikko,

to reproduce a problem, just set your region format in Windows "Region" dialog to "German(Germany)", where "short date" field is dd.MM.yyyy

Unfortunately, can't attach a screenshot here. I'm ready to send all the pictures if it helps.

Best regards, Andrew

Profile picture for user Kurumi

Kurumi

3 weeks 2 days ago

Hi Andrew, After the region…

Hi Andrew,

After the region was changed to Germany, this was able to be repeated. This is fixed in the next version.

BR,
Mikko

Profile picture for user Kurumi

Kurumi

3 weeks 1 day ago

Hi Andrew, This is now fixed…

Hi Andrew,

This is now fixed, and the new version has been released. This was clear after the language was changed to German.

Thank you for pointing this out.

BR,
Mikko

andre538

3 weeks 1 day ago

Thanks a lot!

Thanks a lot!

  • Log in or register to post comments
  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 07/09/2025 - 16:41
    Gurux.Serial.Android 2.0.13
  • Wed, 07/09/2025 - 12:07
    gurux.dlms.c 9.0.2507.0901
  • Sat, 07/05/2025 - 15:04
    Gurux.DLMS.Python 1.0.188
  • Tue, 07/01/2025 - 10:09
    Gurux.DLMS.Python 1.0.187
  • Tue, 07/01/2025 - 09:54
    gurux.dlms.c 9.0.2507.0101

New forum topics

  • Authentication issues (AARQ) with WASION IM300
  • Regarding the dlms android project
  • Unable to read attribute =3 (1.0.94.91.0.255) IC=7 for Indian Metering, while I'm able to read attribute 3 for other Profile generic class
  • Register Activation class (class_id = 9) attribute index 3 data is not visible
  • Load profile
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin