Sha256: 69125980874c88aea8a166a589095da2651637dd9156ab79a00f9ee68113cc42

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2010 Sprout Systems, Inc. and contributors.
//            Portions ©2008-2010 Apple Inc. All rights reserved.
// License:   Licened under MIT license (see license.js)
// ==========================================================================

require('validators/validator');

/**
  This validates a SC.DateTime, used in SC.DateFieldView.
  
  @class
  @extends SC.Validator
  @author Juan Pablo Goldfinger
  @version 1.0
*/
SC.Validator.DateTime = SC.Validator.extend({

  /**
    The standard format you want the validator to convert dates to.
  */
  format: '%d/%m/%Y',

  /**
    if we have a number, then convert to a date object.
  */
  fieldValueForObject: function(object, form, field) {
    if (SC.kindOf(object, SC.DateTime)) {
      object = object.toFormattedString(this.get('format'));
    } else {
      object = null;
    }
    return object;
  },

  /**
    Try to pase value as a date. convert into a number, or return null if
    it could not be parsed.
  */
  objectForFieldValue: function(value, form, field) {
    if (value) {
      value = SC.DateTime.parse(value, this.get('format'));
    }
    return value;
  }

});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sproutcore-1.4.2-java lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js
sproutcore-1.4.2 lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js
sproutcore-1.4.1-java lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js
sproutcore-1.4.1 lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js
sproutcore-1.4.0-java lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js
sproutcore-1.4.0 lib/frameworks/sproutcore/frameworks/foundation/validators/date_time.js