Sha256: 5f1db82fbd2bc5c257f0913e1e4b36562e1dcbffc99a3fc7f867032a33c71df0

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

// ========================================================================
// SproutCore
// copyright 2006-2008 Sprout Systems, Inc.
// ========================================================================

require('validators/validator') ;

/**
  Handle parsing and display of dates.
  
  @class
  @extends SC.Validator
  @author Charles Jolley
  @version 1.0
*/
SC.Validator.Date = SC.Validator.extend(
/** @scope SC.Validator.Date.prototype */ {

  /**
    The standard format you want the validator to convert dates to.
  */
  format: 'NNN d, yyyy h:mm:ss a',
  
  /**
    If true, dates will be converted to a natural language format if
    possible such as "Tomorrow" or "Today".
  */
  naturalLanguage: true,
  
  /**
    if we have a number, then convert to a date object.
  */
  fieldValueForObject: function(object, form, field) {
    var date ;
    if (typeof(object) == "number") {
      date = new Date(object) ;
    } else if (object instanceof Date) { date = object; }
      
    if (date) object = date.format(this.get('format'),this.get('naturalLanguage')) ;
    
    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) {
      var date = Date.parseDate(value) ;
      value = (date) ? date.getTime() : null ;
    }
    return value ;
  }
    
}) ;

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sproutcore-0.9.12 frameworks/sproutcore/validators/date.js
sproutcore-0.9.10 frameworks/sproutcore/validators/date.js
sproutcore-0.9.11 frameworks/sproutcore/validators/date.js
sproutcore-0.9.13 frameworks/sproutcore/validators/date.js
sproutcore-0.9.14 frameworks/sproutcore/validators/date.js
sproutcore-0.9.2 frameworks/sproutcore/validators/date.js
sproutcore-0.9.3 frameworks/sproutcore/validators/date.js
sproutcore-0.9.5 frameworks/sproutcore/validators/date.js
sproutcore-0.9.4 frameworks/sproutcore/validators/date.js
sproutcore-0.9.9 frameworks/sproutcore/validators/date.js
sproutcore-0.9.6 frameworks/sproutcore/validators/date.js
sproutcore-0.9.8 frameworks/sproutcore/validators/date.js
sproutcore-0.9.7 frameworks/sproutcore/validators/date.js