Date Constrained To Only Month and Year

I’m working on creating a model for a set of anthology books. The anthologies themselves reprint back issues of comic books. I want to be able to record the month and year of the comic book being reprinted. The day is always assumed to be the first of the month. For example an issue printed in August of 1982 has a print date of 8/1/82 (but I don’t specify the first).

This is what I’ve come up with so far:

sig Month {}
{
no m:Int | m < 1
no m:Int | m > 12
}

sig Year {}
{
no y:Int | y < 1930
no y:Int | y > 2026
}

sig IssueDate{
month: Month,
year: Year
}


I know I could use an enumerated signature on the month but since I want to have an integer and I want to constrain it to between 1 and 12 it felt like this sig with the sig fact specified was a better approach. For the year I just arbitrarily picked 1930 as my minimum and this year as my max. So I guess what I’d like to ask is this:

1.) Is this a good way to constrain a value to a subset of all possible values?

2.) Any other suggestions on how I might model this?

Alloy is lousy with integers. By default you only get 16 of them -8 … 7. You can ask for more but they are very expensive when you resolve a model. E.g. your year is going to slow down resolving to a crawl since it uses 96 positive ints, so you get 8 bit ints.

It is therefore almost always better to not use ints for domain types.

The primary purpose of Alloy is to test designs. For this you should only use sigs that really play a role in your domain. For most cases, an IssueDate is sufficient because the actual year and month are not really relevant for the problem domain. Only when you have rules that work on months and years do you need to model them and then only model them for what you need.

If you really need months, the enum is rather nice for this: enum Month { Jan, Feb, Mar, … }

Thank you Peter. Too many years of writing software to let go of old validation habits. I need to think more (not less) abstractly. Tough to do when I’m so accustomed to the other way! Thanks for responding!

One of the values of Alloy is that it forces you to think of the essence of your problem. If you do it right you keep removing stuff and then I usually abandon my project because I finally ‘got’ it and can start coding.