Subversion Repository Public Repository

litesoft

Diff Revisions 851 vs 853 for /trunk/Java/core/Anywhere/src/org/litesoft/core/util/TypeConverter.java

Diff revisions: vs.
  @@ -344,83 +344,88 @@
344 344 return temporal.copyWithUpdatedResolution( pTimeRes );
345 345 }
346 346
347 - public static SimpleDate to_SimpleDate( String pFormat, Object pObject )
347 + public static SimpleDate to_SimpleDate( DateRes pDateRes, Object pObject )
348 348 {
349 349 if ( null == pObject )
350 350 {
351 351 return null;
352 352 }
353 - // TODO: XXX
354 - // if ( pObject instanceof SimpleDate )
355 - // {
356 - // SimpleDate temporal = (SimpleDate) pObject;
357 - // if ( temporal.getFormat().equals( pFormat ) )
358 - // {
359 - // return temporal;
360 - // }
361 - // // Fall thru to 'toString' version...
362 - // }
353 + if ( pObject instanceof SimpleDate )
354 + {
355 + return ((SimpleDate) pObject).changeResolution( pDateRes );
356 + }
363 357 if ( pObject instanceof Time )
364 358 {
365 359 throw new IllegalArgumentException( "No convertion supported from SQL Time to Simple Date" );
366 360 }
367 - // TODO: XXX
368 - // if ( pObject instanceof Date )
369 - // {
370 - // return new SimpleDate( pFormat, (Date) pObject );
371 - // }
372 - // if ( pObject instanceof Number )
373 - // {
374 - // return new SimpleDate( pFormat, new Date( ((Number) pObject).longValue() ) );
375 - // }
376 - // if ( pObject instanceof SimpleTimestamp )
377 - // {
378 - // return new SimpleDate( pFormat, ((SimpleTimestamp) pObject).getDate() );
379 - // }
361 + if ( pObject instanceof Date )
362 + {
363 + return new SimpleDate( pDateRes, (Date) pObject );
364 + }
365 + if ( pObject instanceof Number )
366 + {
367 + return new SimpleDate( pDateRes, new Date( ((Number) pObject).longValue() ) );
368 + }
369 + if ( pObject instanceof SimpleTimestamp )
370 + {
371 + return new SimpleDate( pDateRes, (SimpleTimestamp) pObject );
372 + }
380 373 String s = pObject.toString();
381 - // TODO: XXX
382 - // try
383 - // {
384 - // return new SimpleDate( pFormat, new Date( Long.parseLong( s ) ) );
385 - // }
386 - // catch ( NumberFormatException e )
387 - // {
388 - // // Ignore
389 - // }
390 - // try
391 - // {
392 - // return new SimpleDate( pFormat, UtilDateAdaptor.fromUtilDateToString( s ).getWallDate() );
393 - // }
394 - // catch ( IllegalArgumentException e )
395 - // {
396 - // // Ignore
397 - // }
398 - // try
399 - // {
400 - // return new SimpleDate( pFormat, java.sql.Date.valueOf( s ) );
401 - // }
402 - // catch ( IllegalArgumentException e )
403 - // {
404 - // // Ignore
405 - // }
406 - // try
407 - // {
408 - // return SimpleDate.fromYMD( pFormat, s );
409 - // }
410 - // catch ( IllegalArgumentException e )
411 - // {
412 - // // Ignore
413 - // }
414 - // try
415 - // {
416 - // return new SimpleDate( pFormat, SimpleTimestamp.fromString( s ).getDate() );
417 - // }
418 - // catch ( IllegalArgumentException e )
419 - // {
420 - // // Ignore
421 - // }
422 - TemporalParser parser = new TemporalParser( new DateFormat( pFormat ).getFieldOrder() );
423 - return parser.parseDate( pFormat, s, null );
374 + try
375 + {
376 + return new SimpleDate( pDateRes, new Date( Long.parseLong( s ) ) );
377 + }
378 + catch ( NumberFormatException e )
379 + {
380 + // Ignore
381 + }
382 + try
383 + {
384 + return new SimpleDate( pDateRes, UtilDateAdaptor.fromUtilDateToString( s ) );
385 + }
386 + catch ( IllegalArgumentException e )
387 + {
388 + // Ignore
389 + }
390 + try
391 + {
392 + return new SimpleDate( pDateRes, java.sql.Date.valueOf( s ) );
393 + }
394 + catch ( IllegalArgumentException e )
395 + {
396 + // Ignore
397 + }
398 + try
399 + {
400 + return SimpleDate.fromYMD( s ).changeResolution( pDateRes );
401 + }
402 + catch ( IllegalArgumentException e )
403 + {
404 + // Ignore
405 + }
406 + try
407 + {
408 + return new SimpleDate( pDateRes, SimpleTimestamp.fromString( s ) );
409 + }
410 + catch ( IllegalArgumentException e )
411 + {
412 + // Ignore
413 + }
414 + TemporalParser zParser = TemporalParser.YMD;
415 + String zCurrentUserDateFieldOrder = pDateRes.getDateFormat().getFieldOrder();
416 + if ( !zParser.getFieldOrder().equals( zCurrentUserDateFieldOrder ) )
417 + {
418 + try
419 + {
420 + return zParser.parseDate( s, pDateRes, null ); // Try YMD first
421 + }
422 + catch ( IllegalArgumentException e )
423 + {
424 + // Ignore
425 + }
426 + zParser = new TemporalParser( zCurrentUserDateFieldOrder ); // Then User's Current Field Order
427 + }
428 + return zParser.parseDate( s, pDateRes, null );
424 429 }
425 430
426 431 public static TextLines to_TextLines( Object pObject )