I use ISO 8601 to represent dates & durations and all is OK.
But now I need to represent relative dates and durations like:

The date for first day, at midnight, of the next week

All the last month period.

In fact I need to have a syntax for it, I prefer a standard one.
I don't need code (I yet have all the code) but a syntax to store relatives date or durations just like ISO 8601 use "P1Y2M10DT2H30M" for a duration.

A little more detail would help. What technologies are you using? Are you using a rich framework such as Java or .NET? Or is this close-to-the-metal C code for some embedded application?
–
RationalGeekMay 24 '11 at 14:50

In fact I use it to save a choice of period, my software log events and the user may choose to print, every month, the 'last month' events, or every first day of a new trimester, the 'last trimester' event. This syntax is used by some programs, the 'scheduler' in Python or for the end user interface in Delphi.
–
philnextMay 24 '11 at 15:00

Start with a table that contains all of the dates within a reasonable range you'll be working with.
–
JeffOMay 24 '11 at 15:14

@Jeff : I give to the user the possibility to choose all combinaisons of choices (last week, last month, last trimester, 2 last month, 2 last trimesters...) so there is not any 'reasonable' range for it.
–
philnextMay 24 '11 at 19:39

OK it seems to be a good solution, quite close to my own syntax. Do you have any link to documentation ?
–
philnextMay 24 '11 at 19:36

@philnext: sorry, no documentation, unless you count the FogBugz and Jira manuals. You should be able to find them at their respective sites? fogbugz.com and atlassian.com for Jira.
–
Marjan VenemaMay 24 '11 at 19:54

In the Java world Joda Time supports this kind of operation with respect to your locale meaning it adjusts automatically for the small cultural differences if you need it to.

For example you could create a DateTime which is absolute (today) and add it a relative period (today.plusDays(7) to add a week for example). It also supportsmanyways to convey this concept of relative duration depending on your use case.

If you do not use Java, I still suggest you look at it to see what to look for in a good calendar management library for your own environment or give you inspiration on making your own.

Careful here though if you decide to go custom, time and dates are simple concepts but only on the surface. There is a lot of adjustments that need to be done to the time in the background to keep it's absolute (a second is a second) and relative (at noon the sun should be at it's zenith) natures in check. Creating your own implementation is simple until you get errors when dealing with such things, combine the microsecond or more precision of computers and their absolute autistic trait they are quite inept when times come to deal with fuzzy concepts that we humans take for granted.

Thanks for it but I have all the code (in Python & Delphi) for it but I search for a standard syntax for 'the period for the last week' or 'the period of the week 2 weeks ago'. I have an internal syntax but I would found a standard one.
–
philnextMay 24 '11 at 18:25

hooo I see now... sorry I misunderstood the question ! I guess thus far Marjan's answer is the best one, for fairness I'll transfer the upvote I got so it gets on top of mine.
–
NewtopianMay 24 '11 at 21:41

If I understand what you mean correctly, you wish to have a way to say DateTime.NextSunday? If that's the case, as far as I know there isn't a standard you can use for that.

The two examples you gave above are specific examples of a date you need. You would still express the date time using the ISO standard, you just have to prgrammatically define what each means.

How I would do this is in my UI, I'd have a button called "Next Week". Here in Canada, the first day of the week is Sunday, but that's not the same for everyone. Thus I'd write my code like this (c# is my language of choice):