Project

General

Profile

Revision 9e82319e

ID9e82319ebe21706e23e5eaa7c74b3ee6c32f3e0c
Parent 5e7f22d8
Child 0d330678

Added by Andreas Müller about 1 year ago

ref #7644 implement "continued" in TimePeriod, still missing for most of the formats in parser

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/TimePeriod.java
61 61
public class TimePeriod implements Cloneable, Serializable {
62 62
    private static final long serialVersionUID = 3405969418194981401L;
63 63
    private static final Logger logger = Logger.getLogger(TimePeriod.class);
64
    public static final DateTimeFieldType MONTH_TYPE = DateTimeFieldType.monthOfYear();
65 64
    public static final DateTimeFieldType YEAR_TYPE = DateTimeFieldType.year();
65
    public static final DateTimeFieldType MONTH_TYPE = DateTimeFieldType.monthOfYear();
66 66
    public static final DateTimeFieldType DAY_TYPE = DateTimeFieldType.dayOfMonth();
67 67
    public static final DateTimeFieldType HOUR_TYPE = DateTimeFieldType.hourOfDay();
68 68
    public static final DateTimeFieldType MINUTE_TYPE = DateTimeFieldType.minuteOfHour();
69 69

  
70
    public static final Partial CONTINUED = new Partial
71
            (new DateTimeFieldType[]{YEAR_TYPE, MONTH_TYPE, DAY_TYPE},
72
             new int[]{9999, 11, 30});
73

  
70 74
    @XmlElement(name = "Start")
71 75
    @XmlJavaTypeAdapter(value = PartialAdapter.class)
72 76
    @Type(type="partialUserType")
......
528 532
        String result = null;
529 533
        DateTimeFormatter formatter = TimePeriodPartialFormatter.NewInstance();
530 534
        String strStart = start != null ? start.toString(formatter): null;
531
        String strEnd = end != null ? end.toString(formatter): null;
532
        result = CdmUtils.concat("-", strStart, strEnd);
535
        if (isContinued()){
536
            result = CdmUtils.concat("", strStart, "+");
537
        }else{
538
            String strEnd = end != null ? end.toString(formatter): null;
539
            result = CdmUtils.concat("-", strStart, strEnd);
540
        }
533 541

  
534 542
        return result;
535 543
    }
......
602 610
    }
603 611

  
604 612

  
613
    /**
614
     * Shortcut to define that {@link #getEnd() end of period} is defined end
615
     * for a continuous period represented by {@link #CONTINUED}
616
     * @return
617
     */
618
    public boolean isContinued() {
619
        return CONTINUED.equals(end);
620
    }
621
    public void setContinued(boolean isContinued) {
622
        if (isContinued == true){
623
            this.end = CONTINUED;
624
        }
625
    }
626

  
627

  
605 628
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/TimePeriodParser.java
47 47
	//standard
48 48
	private static final Pattern standardPattern =  Pattern.compile("\\s*\\d{2,4}(\\s*-(\\s*\\d{2,4})?)?");
49 49
	private static final String strDotDate = "[0-3]?\\d\\.[01]?\\d\\.\\d{4,4}";
50
	private static final String strDotDatePeriodPattern = String.format("%s(\\s*-\\s*%s?)?", strDotDate, strDotDate);
50
	private static final String strDotDatePeriodPattern = String.format("%s(\\s*-\\s*%s?|\\+)?", strDotDate, strDotDate);
51 51
	private static final Pattern dotDatePattern =  Pattern.compile(strDotDatePeriodPattern);
52 52
	private static final String strSlashDate = "[0-3]?\\d\\/[01]?\\d\\/\\d{4,4}";
53 53
	private static final String strSlashDatePeriodPattern = String.format("%s(\\s*-\\s*%s?)?", strSlashDate, strSlashDate);
......
233 233
			result.setFreeText(periodString);
234 234
		}else {
235 235
			try {
236

  
236 237
				//start
237 238
				if (! StringUtils.isBlank(dates[0])){
238
					dtStart = parseSingleDotDate(dates[0].trim());
239
				    if (dates.length == 1 && dates[0].endsWith("+") && dates[0].length()>1){
240
	                    dates[0] = dates[0].substring(0, dates[0].length()-1);
241
	                    dtEnd = TimePeriod.CONTINUED;
242
	                }
243
				    dtStart = parseSingleDotDate(dates[0].trim());
239 244
				}
240 245

  
241 246
				//end
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/common/TimePeriodTest.java
320 320
		Assert.assertEquals("3.xx.1788-1799", tp1.toString());
321 321
		tp1.setEndMonth(11);
322 322
		Assert.assertEquals("3.xx.1788-11.1799", tp1.toString());
323
		tp1.setContinued(true);
324
		Assert.assertEquals("3.xx.1788+", tp1.toString());
325

  
326
		tp1 = TimePeriod.NewInstance(1788,1799);
327
		tp1.setContinued(true);
328
        Assert.assertEquals("1788+", tp1.toString());
329
        tp1 = TimePeriod.NewInstance((Integer)null);
330
        tp1.setContinued(true);
331
        //this is still undefined, could be something like 'xxxx+' in future
332
        Assert.assertEquals("+", tp1.toString());
323 333
	}
324 334

  
325 335

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/TimePeriodParserTest.java
326 326
        Assert.assertEquals(null, tp.getVerbatimDate());
327 327
    }
328 328

  
329
    @Test
330
    public void testParseContinued() {
331
        String strDate = "1957+";
332
        VerbatimTimePeriod tp = TimePeriodParser.parseStringVerbatim(strDate);
333
        assertNotNull(tp);
334
        Assert.assertTrue(tp.isContinued());
335
        Assert.assertEquals("1957+", tp.toString());
336
        Assert.assertEquals("1957", tp.getYear());
337
        Assert.assertEquals(Integer.valueOf(1957), tp.getStartYear());
338
//        Assert.assertEquals(Integer.valueOf(8), tp.getStartMonth());
339
//        Assert.assertEquals(Integer.valueOf(24), tp.getStartDay());
340
//        Assert.assertEquals("1958", tp.getVerbatimDate());
341

  
342
//        strDate = "1947 publ. 1948";
343
//        tp = TimePeriodParser.parseStringVerbatim(strDate);
344
//        assertNotNull(tp);
345
//        Assert.assertEquals("1947 [\"1948\"]", tp.toString());
346
//        Assert.assertEquals("1947", tp.getYear());
347
//        Assert.assertEquals(Integer.valueOf(1947), tp.getStartYear());
348
//        Assert.assertEquals("1948", tp.getVerbatimDate());
349

  
350

  
351
    }
329 352

  
330 353

  
331 354
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)