1

I am trying to work with Quartz.NET in F# and have run into a few issues with the fact that, while Quartz.NET is usable in F#, there does not seem to be much documentation on it, and I've had some difficulty with differences between it and what can find in C#.

One issue I have currently run into is setting SystemTime such as shown in this question, Quartz.net + testing with SystemTime.UtcNow.

I could be wrong, but I thought that the code in F# should be:

SystemTime.Now = fun () -> DateTime(someDate)
SystemTime.UtcNow = fun () -> DateTime(someDate)

But I get an error about either too many arguments or function used where not expected. If I just use the DateTime constructor, I get an error related to the fact it is expecting a function.

Community
  • 1
  • 1
Sean
  • 83
  • 1
  • 7
  • Welcome to Stack Overflow. If you have two questions, then please ask two different questions. I've edited out your second question (but you can get it back via the version history of your question). – Mark Seemann Apr 17 '15 at 18:25
  • I apologize. Though since both were related to using Quartz.net in F# would be bore concise to ask them together. I'll post a separate question for the other one later then. – Sean Apr 17 '15 at 19:00
  • No worries. You'll have a better chance of getting your questions answered if you post each separately, because some people may be able to answer one, and other people another. If you get more answers to a single question, it'll also make it easier for you to mark one of them as the correct answer. – Mark Seemann Apr 18 '15 at 08:31

1 Answers1

1

The single = is an equality comparison operation. If you want to do assignment, use the <- assignment operator.

Apart from that, F# functions aren't the same as Func<T>. Normally, when you use them as method arguments, the conversion happens automatically, but in this case, it seems you'll need to explicitly perform the conversion:

open System
open Quartz

SystemTime.Now <- 
    Func<DateTimeOffset>(
        fun () -> DateTimeOffset(DateTime(2015, 4, 18), TimeSpan.FromHours 2.))
SystemTime.UtcNow <- 
    Func<DateTimeOffset>(
        fun () -> DateTimeOffset(DateTime(2015, 4, 18), TimeSpan.FromHours 2.))

To invoke them from F# is also a bit more involved:

> SystemTime.Now.Invoke();;
val it : DateTimeOffset = 18.04.2015 00:00:00 +02:00
> SystemTime.UtcNow.Invoke();;
val it : DateTimeOffset = 18.04.2015 00:00:00 +02:00
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • Thank you but I still get an error of "This function takes too many arguments or is used in a context where a function is not expected." – Sean Apr 17 '15 at 18:32
  • Basically was using someDate just as filler rather than type out an actual date in the question since figured didn't matter. I think because just filled out an easily entered date while trying to get the code to work line was actually, `SystemTime.Now <- fun () -> DateTime(2015,1,1,1,1,1)` However did come across something should use a DateTimeOffset instead so have also tried the following now, `SystemTime.Now <- fun () -> DateTimeOffset(DateTime(2015,1,1,1,1,1))` But both give the same error. – Sean Apr 17 '15 at 18:58