Skip to content

Commit

Permalink
length check time better
Browse files Browse the repository at this point in the history
d-mmm-yy is valid
dd-mmm-yy is valid
  • Loading branch information
cliffclick committed Aug 8, 2014
1 parent 9f3d610 commit f7901b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions py/testdir_multi_jvm/test_parse_time_fvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ def getRandomTimeStamp():
# "yyyy-MM-dd HH:mm:ss.SSS",

if timestampFormat==0:
a = "%s-%s-%s" % (day, month, year)
a = "%s-%s-%02d" % (day, month, year)
elif timestampFormat==1:
a = "%s-%s-%s" % (year, month, day)
a = "%04d-%s-%s" % (year, month, day)
elif timestampFormat==2:
a = "%s-%s-%s %s:%s:%s" % (year, month, day, hour, minute, second)
a = "%04d-%s-%s %s:%s:%s" % (year, month, day, hour, minute, second)
# elif timestampFormat==3:
else:
a = "%s-%s-%s %s:%s:%s:%s" % (year, month, day, hour, minute, second, milli)
a = "%04d-%s-%s %s:%s:%s:%s" % (year, month, day, hour, minute, second, milli)
return a

def rand_rowData(colCount=6):
Expand Down Expand Up @@ -211,7 +211,7 @@ def setUpClass(cls):
SEED = h2o.setup_random_seed()
localhost = h2o.decide_if_localhost()
if (localhost):
h2o.build_cloud(1,java_heap_GB=10,use_flatfile=True)
h2o.build_cloud(1,java_heap_GB=1,use_flatfile=True)
else:
h2o_hosts.build_cloud_with_hosts()

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/water/fvec/ParseTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ private static long attemptTimeParse_01( ValueString str ) {
return encodeTimePat(new DateTime(yy,MM,dd,HH,mm,ss).getMillis()+SS,1);
}

// DD-MMM-YY
private static long attemptTimeParse_2( ValueString str ) {
final byte[] buf = str.get_buf();
int i=str.get_off();
final int end = i+str.get_length();
while( i < end && buf[i] == ' ' ) i++;
if ( i < end && buf[i] == '"' ) i++;
if( (end-i) < 8 ) return Long.MIN_VALUE;
if( (end-i) < 8 ) return Long.MIN_VALUE; // Shortest date: d-mm-yy, only 7 chars
int yy=0, MM=0, dd=0;
dd = digit(dd,buf[i++]);
if( buf[i] != '-' ) dd = digit(dd,buf[i++]);
Expand All @@ -129,8 +130,10 @@ private static long attemptTimeParse_2( ValueString str ) {
MM++; // 1-based month
if( buf[i++] != '-' ) return Long.MIN_VALUE;
yy = digit(yy,buf[i++]); // 2-digit year
if( i >= buf.length ) return Long.MIN_VALUE;
yy = digit(yy,buf[i++]);
if( end-i>=2 && buf[i] != '"' ) {
if( i >= buf.length+1 ) return Long.MIN_VALUE;
yy = digit(yy,buf[i++]); // 4-digit year
yy = digit(yy,buf[i++]);
} else {
Expand Down

0 comments on commit f7901b8

Please sign in to comment.