0

I'm trying to add validation for date type in emf.ecore 2.23 as following examples

invariant validation1:
        self.startDate.before(self.terminationDate);

or

invariant validation2:
            self.startDate < self.terminationDate;

Using this link https://wiki.eclipse.org/EMF/Recipes#Recipe:_Generating_data_types_that_support_date.2Ftime_format, I included the date java.util.Date, but ocl still doesn't recognize methods. I also failed to add an EAnnotation type http:///org/eclipse/emf/ecore/util/DateConversionDelegate.

1 Answers1

1

Unfortunately Ecore models EDate as an EDataType for which EMF does not support user-defined methods. OCL support 'finds' only =/<>. Once Eclipse OCL support expands to support use of underlying language APIs this is a good use case for improvement. Comment added to https://bugs.eclipse.org/bugs/show_bug.cgi?id=370087

Today it is an EMF 'bug'. EDate should have been declared as an EClass, but that would have created other difficulties.

Again today, the workaround is to declare and manually implement a stateless EDateHelper class with methods such as before(date1 : EDate, date2 : EDate) : Boolean.

Ed Willink
  • 1,205
  • 7
  • 8
  • 1
    When I installed new version of Java, I can use operators <,> and = to compare dates, instead of using isBefore and other methods. Everything works fine, thank you Ed. – Tijana Lalošević Mar 15 '21 at 18:48