- 
                Notifications
    
You must be signed in to change notification settings  - Fork 6
 
Issue #5: Support for DATE/TIME extraction. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            tdanford
  wants to merge
  2
  commits into
  datacleaner:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
tdanford:datetime-formats
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            8 changes: 8 additions & 0 deletions
          
          8 
        
  sas/src/main/java/org/eobjects/metamodel/sas/DateConversionException.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.eobjects.metamodel.sas; | ||
| 
     | 
||
| public class DateConversionException extends RuntimeException { | ||
| 
     | 
||
| public DateConversionException(String msg, Object ... values) { | ||
| super(String.format(msg, values)); | ||
| } | ||
| } | 
        
          
          
            85 changes: 85 additions & 0 deletions
          
          85 
        
  sas/src/main/java/org/eobjects/metamodel/sas/DateTimeConverter.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package org.eobjects.metamodel.sas; | ||
| 
     | 
||
| import org.joda.time.DateTime; | ||
| import org.joda.time.Period; | ||
| 
     | 
||
| public class DateTimeConverter { | ||
| 
     | 
||
| private static final int MINYEAR= 1, MAXYEAR=9999, MINDAYS=-999999999, MAXDAYS=999999999; | ||
| 
     | 
||
| public DateTime datetimeToJava(int dateSeconds) { | ||
| DateTime dt = new DateTime(1960, 1, 1, 0, 0).plusSeconds(dateSeconds); | ||
| return dt; | ||
| } | ||
| 
     | 
||
| public DateTime date9ToJava(int date9) { | ||
| 
     | 
||
| /* | ||
| * This bounding [MINDAYS, MAXDAYS] isn't actually part of the spec -- | ||
| * it's a restriction that is inherited from the python implementation | ||
| * of the sas7bdat format (and the use of Python datetimes in that | ||
| * code), and it's here to make sure that the results of the two packages | ||
| * are mutually comparable. | ||
| */ | ||
| if(date9 < MINDAYS || date9 > MAXDAYS) { | ||
| throw new DateConversionException( | ||
| "date9=%d must fall within the range [%d, %d]", | ||
| date9, MINDAYS, MAXDAYS); | ||
| } | ||
| 
     | 
||
| DateTime dt = new DateTime(1960, 1, 1, 0, 0).plusDays(date9); | ||
| 
     | 
||
| /* | ||
| * Same as above -- this is a Python-ism, which seems reasonable | ||
| * (until we start collecting clinical study data in the year 10,000) | ||
| * and is here to make sure that the two code bases are as functionally | ||
| * equivalent as possible (which helps for testing). | ||
| */ | ||
| if(dt.getYear() < MINYEAR || dt.getYear() > MAXYEAR) { | ||
| throw new DateConversionException( | ||
| "year=%d must fall within the range [%d, %d]", | ||
| dt.getYear(), MINYEAR, MAXYEAR); | ||
| } | ||
| 
     | 
||
| return dt; | ||
| } | ||
| 
     | 
||
| public Period time5ToJavaPeriod(int time5) { | ||
| /* | ||
| * Carry over Python-determined time and timedelta bounds, see comment above. | ||
| */ | ||
| if(time5 < MINDAYS || time5 > MAXDAYS) { | ||
| throw new DateConversionException( | ||
| "time5=%d must fall within the range [%d, %d]", | ||
| time5, MINDAYS, MAXDAYS); | ||
| } | ||
| 
     | 
||
| /* | ||
| * This is confusing to me -- I don't know why, if we're only | ||
| * measuring seconds-within-a-day for a TIME-formatted value, | ||
| * we are storing _the total number of seconds since Jan 1, 1960_ | ||
| * BUT that appears to be what's going on here. <SIGH> | ||
| */ | ||
| DateTime dt = new DateTime(1960, 1, 1, 0, 0).plusSeconds(time5); | ||
| 
     | 
||
| /* | ||
| * Carry over Python-determined time and timedelta bounds, see comment above. | ||
| */ | ||
| if(dt.getYear() < MINYEAR || dt.getYear() > MAXYEAR) { | ||
| throw new DateConversionException( | ||
| "year=%d must fall within the range [%d, %d]", | ||
| dt.getYear(), MINYEAR, MAXYEAR); | ||
| } | ||
| 
     | 
||
| /* | ||
| * for TIME values, we only return the hours/minutes/seconds | ||
| * as a separate Period value. | ||
| */ | ||
| int hours = dt.getHourOfDay(); | ||
| int minutes = dt.getMinuteOfHour(); | ||
| int seconds = dt.getSecondOfMinute(); | ||
| int millis = dt.getMillisOfSecond(); | ||
| 
     | 
||
| return new Period(hours, minutes, seconds, millis); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -26,5 +26,5 @@ | |
| */ | ||
| public enum SasColumnType { | ||
| 
     | 
||
| NUMERIC, CHARACTER; | ||
| NUMERIC, CHARACTER, DATE, TIME; | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not ship with any specific logging framework except for the facade provided by slf4j. It would be fine to include this as a test-scoped dependency if needed, but I would like to prevent that we make logging framework decisions for the end users of the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll scope it as 'test', thanks.