There is a build-in function DateQ
. It is a very nice function. For example it knows that 2000 is a leap year, but 2100 is not
Needs["Calendar`"]
DateQ[{2000, 2, 29}]
DateQ[{2100, 2, 29}]
True
False
NowDateQ
can take hours, minutes and seconds, but it ignores their values. See definition (there is no Calendar`Private`r
in the rhs):
DateQ[{Calendar`Private`y_, Calendar`Private`m_, Calendar`Private`d_,
Calendar`Private`r___}, Calendar`Private`opts___] :=
Module[{Calendar`Private`cal =
Calendar /. Flatten[{Calendar`Private`opts, Options[DateQ]}]},
Calendar`Private`dateQ[Calendar`Private`y, Calendar`Private`m,
Calendar`Private`d, Calendar`Private`cal]]
However you can implement your own dateTimeQ
dateTimeQ[{h_, m_, d_, hour_, min_, sec_}] :=
MatchQ[{h, m, d, hour, min, sec}, {__Integer}] && DateQ[{h, m, d}] &&
0 <= hour < 24 && 0 <= min < 60 && 0 <= sec < 60;
dateTimeQ[___] := False
and convert
convert[quants : {{_?dateTimeQ, _Integer} ..}, prices : {{_?dateTimeQ, _Real} ..}] /;
Length@quants == Length@prices := OK;
quant = {{{2012, 1, 1, 9, 30, 7}, 150},
{{2012, 1, 1, 9, 30, 12}, 130},
{{2012, 1, 1, 9, 30, 33}, 470}};
price = {{{2012, 1, 1, 9, 30, 7}, 1.50},
{{2012, 1, 1, 9, 30, 33}, 1.30},
{{2012, 1, 1, 9, 30, 33}, 4.70}};
convert[quant, price]
OK