time | calls | line |
---|
| | 310 | function [format] = getformat(str)
|
| 3 | 311 | format = '';
|
0.01 | 3 | 312 | formatstr = cell(11,1);
|
| 3 | 313 | formatstr(1) = {'dd-mmm-yyyy HH:MM:SS'};
|
| 3 | 314 | formatstr(2) = {'dd-mmm-yyyy'};
|
| 3 | 315 | formatstr(3) = {'mm/dd/yy'};
|
| 3 | 316 | formatstr(4) = {'mm/dd'};
|
| 3 | 317 | formatstr(5) = {'HH:MM:SS'};
|
| 3 | 318 | formatstr(6) = {'HH:MM:SS PM'};
|
| 3 | 319 | formatstr(7) = {'HH:MM'};
|
| 3 | 320 | formatstr(8) = {'HH:MM PM'};
|
| 3 | 321 | formatstr(9) = {'mm/dd/yyyy'};
|
| 3 | 322 | formatstr(10) = {'dd-mmm-yyyy HH:MM'}; %used by finance
|
| 3 | 323 | formatstr(11) = {'dd-mmm-yy'}; %used by finance
|
| | 324 |
|
| 3 | 325 | AlphaFormats = [1 1 0 0 0 1 0 1 0 1 1];
|
| | 326 | %[1 2 6 8 10 11];
|
| 3 | 327 | SlashFormats = [ 0 0 1 1 0 0 0 0 1 0 0];
|
| | 328 | %[3 4 9];
|
| 3 | 329 | TwoSlashFormats = [ 0 0 1 0 0 0 0 0 1 0 0];
|
| | 330 | %[3 9];
|
| 3 | 331 | DashFormats = [ 1 1 0 0 0 0 0 0 0 1 1];
|
| | 332 | %[1 2 10 11];
|
| 3 | 333 | ColonFormats = [1 0 0 0 1 1 1 1 0 1 0];
|
| | 334 | %[1 5 6 7 8 10];
|
| 3 | 335 | TwoColonFormats = [1 0 0 0 1 1 0 0 0 0 0];
|
| | 336 | %[1 5 6];
|
| 3 | 337 | SpaceFormats = [1 0 0 0 0 1 0 1 0 1 0];
|
| | 338 | %[1 6 8 10];
|
| | 339 |
|
| 3 | 340 | bMask = [ 1 1 1 1 1 1 1 1 1 1 1];
|
| | 341 |
|
| 3 | 342 | if length(str) > 1
|
| | 343 | str = str(1,1);
|
| | 344 | end
|
| 3 | 345 | str = strtrim(char(str));
|
| 3 | 346 | slashes = strfind(str, '/');
|
| 3 | 347 | if ~isempty(slashes)
|
| | 348 | bMask = bMask & SlashFormats;
|
| | 349 | if (~isempty(slashes) && slashes(1) == 2)
|
| | 350 | if (length(slashes) > 1 && slashes(2) == 4)
|
| | 351 | str = ['0' str(1:slashes(1)) '0' str(slashes(1)+1:end)];
|
| | 352 | else
|
| | 353 | str = ['0' str];
|
| | 354 | end
|
| | 355 | elseif (length(slashes) > 1 && slashes(2) - slashes(1) == 2)
|
| | 356 | str = [str(1:slashes(1)) '0' str(slashes(1)+1:end)];
|
| | 357 | end
|
| | 358 | if length(slashes) > 1
|
| | 359 | bMask = bMask & TwoSlashFormats;
|
| | 360 | else
|
| | 361 | bMask = bMask & ~TwoSlashFormats;
|
| | 362 | end
|
| 3 | 363 | else
|
| 3 | 364 | bMask = bMask & ~SlashFormats;
|
| 3 | 365 | end
|
| | 366 |
|
| 3 | 367 | dashes = strfind(str,'-');
|
| 3 | 368 | if ~isempty(dashes)
|
| 3 | 369 | bMask = bMask & DashFormats;
|
| 3 | 370 | if (~isempty(dashes) && dashes(1) == 2)
|
| | 371 | str = ['0' str];
|
| | 372 | end
|
| | 373 | else
|
| | 374 | bMask = bMask & ~DashFormats;
|
| | 375 | end
|
| | 376 |
|
| 3 | 377 | colons = strfind(str,':');
|
| 3 | 378 | if ~isempty(colons)
|
| 3 | 379 | bMask = bMask & ColonFormats;
|
| 3 | 380 | if (~isempty(colons)) && (colons(1) == 2) && (length(str) - colons(end) <= 3)
|
| | 381 | str = ['0' str];
|
| | 382 | end
|
| 3 | 383 | if length(colons) > 1
|
| 3 | 384 | bMask = bMask & TwoColonFormats;
|
| | 385 | else
|
| | 386 | bMask = bMask & ~TwoColonFormats;
|
| | 387 | end
|
| | 388 | else
|
| | 389 | bMask = bMask & ~ColonFormats;
|
| | 390 | end
|
| | 391 |
|
| 3 | 392 | spaces = strfind(str,' ');
|
| 3 | 393 | if ~isempty(spaces)
|
| 3 | 394 | bMask = bMask & SpaceFormats;
|
| | 395 | else
|
| | 396 | bMask = bMask & ~SpaceFormats;
|
| | 397 | end
|
| | 398 |
|
| 3 | 399 | for i = 1:11
|
| 3 | 400 | if bMask(i)
|
| 3 | 401 | try
|
| 3 | 402 | dtnumber = datenum(str, char(formatstr(i)));
|
0.01 | 3 | 403 | str1 = dateformverify(dtnumber,char(formatstr(i)), false);
|
| 3 | 404 | if (strcmpi(str, strtrim(str1)) == 1)
|
| 3 | 405 | format = char(formatstr(i));
|
| 3 | 406 | break;
|
| | 407 | end
|
| | 408 | catch exception %#ok<NASGU>
|
| | 409 | end
|
| | 410 | if AlphaFormats(i)
|
| | 411 | try
|
| | 412 | str1 = dateformverify(dtnumber,char(formatstr(i)),true);
|
| | 413 | if (strcmpi(str, strtrim(str1)) == 1)
|
| | 414 | format = char(formatstr(i));
|
| | 415 | break;
|
| | 416 | end
|
| | 417 | catch exception %#ok<NASGU>
|
| | 418 | end
|
| | 419 | end
|
| | 420 | end
|
| | 421 | end
|
| 3 | 422 | end
|