code: public int getShardNumber(DBObject dbObj) {
          if (!isSharded()) {
              return 0;
          }
          
          String value = dbObj.getFieldValue(getShardingField().getName());
          if (value == null) {
              return 0;
          }
          Date shardingFieldValue = Utils.dateFromString(value);
          return computeShardNumber(shardingFieldValue);
      }
docs: Determine the shard number of the given object for this table. If this table is
  not sharded or the object has no value for its sharding field
  (see {@link #getShardingField()}), the shard number is 0. Otherwise, the
  sharding-field value is used to determine the shard number based on the table's
  sharding start and granularity.
  <p>
  Note: The caller must ensure that if a value exists for the sharding-field, it is
  loaded into the given DBObject. Otherwise, this method will incorrectly assume the
  sharding value has not been set and therefore imply shard 0.
  
  @param dbObj     {@link DBObject} to determine shard number.
  @return          0 if the object's owning table is not sharded, the object has no
  sharding-field value, or the object's sharding field value places
  it before sharding was started. Otherwise, the value is &gt; 0.