bulldog2011/nano

Nano doesn't handle all valid formats of date string

tomaszgrygo opened this issue · 3 comments

Nano recognizes date format by length of string. But some of the valid formats are not recognized. For example:
"yyyy-MM-dd'T'HH:mm:ssZ"
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"

Hi,

Nano is just a small libary targeting android platform, supporting all different date formats may not only involve complexity and effort, but lead to bigger footprint.

You have a few options:

  1. change the data format string in DateTransform class at runtime, these format strings are static but not final.
    https://github.com/bulldog2011/nano/blob/master/src/main/java/com/leansoft/nano/transform/DateTransform.java
  2. customize your own DateTransorm class which implements Transformable interface, then register this class with Transformer at runtime.
    https://github.com/bulldog2011/nano/blob/master/src/main/java/com/leansoft/nano/transform/DateTransform.java
    https://github.com/bulldog2011/nano/blob/master/src/main/java/com/leansoft/nano/transform/Transformer.java
  3. change the nano source directly.

Hope this can help.

Thx for your suggestion!
-William

Can you add handling of two more formats in the class DateTransform? It should not break any existing functionality.
...
public static String FULL_Z = "yyyy-MM-dd'T'HH:mm:ssZ";
public static String FULL_SSS_Z = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
...
public static String getPattern(String text) {
int length = text.length();

    if(length > 28) {
       return FULL_SSS_Z;
    }
    if(length > 24) {
       return FULL_Z;
    }
    if(length > 23) {
       return FULL; 
    }
    if(length > 20) {
       return LONG;
    }
    if(length > 11) {
       return NORMAL;
    }
    return SHORT;
}

Hi,

Thx for your suggestion, I will update the source and let know when it is done.

Thx!
-William