OCL at0运算符语法错误:Timespan适配及OCL语法参考求助
Hey there! Let's work through your issues step by step:
1. Does at0 support the Timespan type?
Nope, that's exactly why you're seeing a syntax error. The at0 operator in MDriven's OCL implementation is a collection-focused operator—it’s designed to pull the first element from sequences, sets, or bags. Since Timespan is a single value type (not a collection), applying at0 to it doesn’t make logical sense, hence the syntax error.
2. How to create a specific Timespan duration in OCL?
MDriven’s OCL dialect has a dedicated Duration class with static methods to build Timespan values cleanly. Here are the most practical approaches:
- To create a 10-hour Timespan (matching your use case):
Duration.hours(10) - For more precise, combined durations, you can chain methods:
Duration.days(1).hours(2).minutes(30).seconds(15) - If you need to assign this directly to your
Employeeinstance’sHoursWorkedproperty, your expression would look like:Employee.allInstances()->first().HoursWorked := Duration.hours(10)
3. Recommended OCL Reference Wiki
For the most accurate, MDriven-specific OCL syntax and expressions, stick to the MDriven OCL Reference Wiki. It covers every supported operator, type handling (including Timespan/Duration), collection operations, and MDriven-specific extensions—way more aligned with your timesheet project than generic OCL resources. If you want to dive into standard OCL fundamentals, the OMG OCL Specification is also a solid baseline, but the MDriven wiki will be your go-to for day-to-day work.
内容的提问来源于stack exchange,提问作者Gustaf

