title: Parsing complex string
body: <p>The problem:</p>
  
  <p>User send a string through an html field and ask the system to retrive rows 
  from database.</p>
  
  <p>The string is a partial or complete representation of a full datetime.</p>
  
  <p>The complete format would be "yyyy-mm-ddThh:ii:ss.ss+hh:ii"</p>
  
  <p>but User can also send a partial format "yyyy-dd", "mm-dd", "hh" and so on..</p>
  
  <p>I need to build a process that translate the user input in the concrete representation.</p>
  
  <p>I've take a look on Builder pattern to programmaticaly build all the parts of the datetime.</p>
  
  <p>I also look at Interpreter pattern for parsing the user input an tell the builder what part is needed.</p>
  
  <p>Questions:</p>
  
  <p>could this be the right way?</p>
  
  <p>how can I parse an undefined string (with a wide range of combination) into a concrete class representation?</p>
  
  <p>A simplified bit of code:</p>
  
  <pre><code>class Director {
   $interpreter;
   $builder;
  
   public function __construct( $interpreter, $builder ) {
    $this-&gt;interpreter = $interpreter;
    $this-&gt;builder = $builder;
   }
  
   public function buildFromString( $format ) {
    $this-&gt;interpreter-&gt;parse( $format );
   }
  }
  
  class Interpreter {
  
   public function parse( $format ) {
    //a good solution to parse the undefined input string
   }
  }
  </code></pre>
  
  <p>Thanks</p>
  
  <p>------------------- added
  because this process can lead to a wide range of misanderstanding, if a user enter "10" the UI ask user to define if he want the "year 10", "month 10" or "minute 10" but this is out of the question.</p>