ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 252 forks source link

constructor bug #237

Closed michaelrolnik closed 1 year ago

michaelrolnik commented 1 year ago

The class has two constructors

   public PrettyTimeParser(TimeZone timezone)
   {
      parser = new Parser(timezone);
   }

   /**
    * Create a new {@link PrettyTimeParser} with the current system default {@link TimeZone}.
    */
   public PrettyTimeParser()
   {
      this(TimeZone.getDefault());
      for (int hours = 0; hours < 24; hours++)
         for (int min = 0; min < 60; min++)
            translations.put(provideRepresentation(hours * 100 + min), "" + hours * 100 + min);
      translations.put(provideRepresentation(60), "" + 60);
      translations.put(provideRepresentation(70), "" + 70);
      translations.put(provideRepresentation(80), "" + 80);
      translations.put(provideRepresentation(90), "" + 90);
      translations.put(provideRepresentation(100), "" + 100);

      periods.add("morning");
      periods.add("afternoon");
      periods.add("evening");
      periods.add("night");
      periods.add("am");
      periods.add("pm");
      periods.add("ago");
      periods.add("from now");
   }

in case the first constructor is used translations is not initialized

lincolnthree commented 1 year ago

Hey @michaelrolnik, you're right! Good find. I'll work on fixing this :)