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