1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 sc_require('validators/validator');
  9 
 10 /**
 11   This validates a SC.DateTime, used in SC.DateFieldView.
 12   
 13   @class
 14   @extends SC.Validator
 15   @author Juan Pablo Goldfinger
 16   @version 1.0
 17 */
 18 SC.Validator.DateTime = SC.Validator.extend({
 19 
 20   /**
 21     The standard format you want the validator to convert dates to.
 22   */
 23   format: '%d/%m/%Y',
 24 
 25   /**
 26     if we have a number, then convert to a date object.
 27   */
 28   fieldValueForObject: function(object, form, field) {
 29     if (SC.kindOf(object, SC.DateTime)) {
 30       object = object.toFormattedString(this.get('format'));
 31     } else {
 32       object = null;
 33     }
 34     return object;
 35   },
 36 
 37   /**
 38     Try to pass value as a date. convert into a number, or return null if
 39     it could not be parsed.
 40   */
 41   objectForFieldValue: function(value, form, field) {
 42     if (value) {
 43       value = SC.DateTime.parse(value, this.get('format'));
 44     }
 45     return value;
 46   }
 47 
 48 });
 49