cancel
Showing results for 
Search instead for 
Did you mean: 

Date.toLocaleString not working

SOLVED
Highlighted
Occasional Contributor

Date.toLocaleString not working

Hello there,

 

I have a question regarding the Date object in JavaScript.

I want to use the following:

function myFunction()
{
  ...
  var myDate = new Date(year, month-1, day);
  var options = { year: 'numeric', month: '2-digit', day: '2-digit' };

  Log.Message("myDate...", "myDate is: " + myDate.toLocaleString('de-DE', options));
  // expected: 02.06.2020
  // result: Mon Jun 02 2020 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
}

 as you can see in my test log message I get a different result.

does TestComplete not support this method or am I using it wrong?

 

the ECMAScript specification of the Date object is this: https://www.ecma-international.org/ecma-262/6.0/#sec-date-objects

and TestComplete uses ECMAScript 6 for JavaScript, as it is stated here: https://support.smartbear.com/viewarticle/77297/

so I thought I can use this method of Date.

 

any suggestions? help?

 

 

thanks in advance,

Kevin

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Date.toLocaleString not working

The problem with .toLocaleString not working as documented in JavaScript documentation should be raised as a support issue directly with SmartBear.  I reproduced the problem and, you are correct, counter to JavaScript documentation, the method is not operating as expected.

 

In the meantime, consider using https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/datetimetoformat... to create your own formatting if there's a particular formatting you want for dates.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

Re: Date.toLocaleString not working

The problem with .toLocaleString not working as documented in JavaScript documentation should be raised as a support issue directly with SmartBear.  I reproduced the problem and, you are correct, counter to JavaScript documentation, the method is not operating as expected.

 

In the meantime, consider using https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/datetimetoformat... to create your own formatting if there's a particular formatting you want for dates.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted
Community Hero

Re: Date.toLocaleString not working

The problem [...] should be raised as a support issue directly with SmartBear

And the link to Support just in case: https://support.smartbear.com/message/?prod=TestComplete

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

Re: Date.toLocaleString not working

Thanks to both of you, I highly appreciate that.

 

As @tristaanogre mentions, I use the aqConvert for now, thank you for suggesting.

Support issue will be created.

Highlighted
Occasional Contributor

Re: Date.toLocaleString not working

FYI: last friday I got a reply from the TestComplete Support.

it is mentioned in the documentation, that the Internationalization API is not supported in javascript here: https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript.html#Unsupported

 

and as the Support suggested, I opened a feature request to implement this functionality here: https://community.smartbear.com/t5/TestComplete-Feature-Requests/Internationalization-API-Support/id...

 

cheers.

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
A new challenge is here!

Create a function to drag one element to another for the TechCorner tag!

Will you dare to take the challenge?


Scripts created in July:
- Passing custom command-line arguments as a test parameter
Top Kudoed Authors