-3

I try to parse a date in the dd.mm.yyyyformat: Globalize.parseDate(value, "dd.MM.yyyy", "en"); but globalize crashes with errors:

Uncaught Error: E_INVALID_PAR_TYPE: Invalid options parameter (dd.mm.yyyy). Plain Object expected.
at createError (globalize.js:105)
at validate (globalize.js:182)
at validateParameterType (globalize.js:257)
at validateParameterTypePlainObject (globalize.js:295)
at Function.Globalize.dateParser.Globalize.dateParser (date.js:1853)
at Function.Globalize.parseDate.Globalize.parseDate (date.js:1908)
at $.validator.methods.date (Index:1891)
at $.validator.check (jquery.validate.js:759)
at $.validator.checkForm (jquery.validate.js:450)

Linked script files:

<script src="/Scripts/cldr.js"></script>
<script src="/Scripts/globalize.js"></script>
<script src="/Scripts/globalize/message.js"></script>
<script src="/Scripts/globalize/number.js"></script>
<script src="/Scripts/globalize/date.js"></script>

How can I fix it?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    Have you tried reading the documentation? What makes you think those are valid `parseDate` parameters? – JJJ Feb 10 '17 at 08:26
  • Could we see your code? i wish to help but it's quite vague. – FreedomPride Feb 10 '17 at 08:28
  • @JJJ, yeah, I read it [here](https://github.com/globalizejs/globalize#date-module). But it's very short and I got a nothing from it. So, I found a [sample](http://stackoverflow.com/questions/6906725/unobtrusive-validation-in-chrome-wont-validate-with-dd-mm-yyyy). – Denis Sologub Feb 10 '17 at 08:30
  • 1
    That sample is for an old version of the library. The documentation you linked to is not "very short": it says `.parseDate( value [, options] )` is an alias for `.dateParser( [options] )( value )` and that has comprehensive documentation ([here](https://github.com/globalizejs/globalize/blob/master/doc/api/date/date-parser.md) and [here](https://github.com/globalizejs/globalize/blob/master/doc/api/date/date-formatter.md)). – JJJ Feb 10 '17 at 08:32
  • @JJJ, thank you for link, it is more clear for me. – Denis Sologub Feb 10 '17 at 08:36

1 Answers1

2

You need to pass the function a value and then an options object.

Globalize.locale('en');
Globalize.parseDate(value, {
    skeleton: 'dd.MM.yyyy'
});

You can find the documentation for this here.

Alexis Tyler
  • 1,394
  • 6
  • 30
  • 48
  • 1
    Thank you, it works perfect! Although, I got a new bug I think that it doesn't load all cldr js files, so I will try to load these and check again. But the current error disappeared. – Denis Sologub Feb 10 '17 at 08:34
  • 1
    Make sure to read the docs as they have most of this stuff in them. I've never used this before and it took me seconds to find the reason it wasn't working. – Alexis Tyler Feb 10 '17 at 09:49
  • The problem is not in docs, the problem that I very bad know JS but docs orientied on this. – Denis Sologub Feb 10 '17 at 09:52