2
$\begingroup$

I'd like to write a function that behaves one way when the argument is a Mathematica date, such as {2013,12,15}, or with added hours, minutes and seconds if necessary. And the function needs to do something different with strings that will look like

2013 Month 02

I see that I can specify List, as in f[x_List] and f[x_String] that will do what I want as long as I don't mess up the arguments. Is there way to be more specific about the patterns that are allowed?

$\endgroup$
  • $\begingroup$ You can be as specific as you want tutorial/Putting constraints on patterns Anything in particular? $\endgroup$ – ssch Oct 29 '13 at 1:56
  • $\begingroup$ so you only want to enter dates as lists or do you want to enter them as strings as well and differentiate between non-date strings? $\endgroup$ – Mike Honeychurch Oct 29 '13 at 2:04
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/34338/… $\endgroup$ – RunnyKine Oct 29 '13 at 6:36
  • $\begingroup$ I'll just use the standard mma format since I'm reading the dates in from a file. $\endgroup$ – Mitchell Kaplan Oct 29 '13 at 19:12
  • $\begingroup$ @MitchellKaplan Is it your earlier account: Mitchell Kaplan? If yes, the both should be merged. $\endgroup$ – Artes Oct 31 '13 at 16:10
2
$\begingroup$

There is a DateQ in the Calendar package. You can test the head of DateList["string"] to make your own dateStringQ. So f[x_?DateQ] and f[x_?dateStringQ] will do.

$\endgroup$
  • $\begingroup$ Thanks, I didn't know I could do that. $\endgroup$ – Mitchell Kaplan Oct 29 '13 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.