Working with TimeSpans and DateTimes

As if you didn’t have enough to worry about – um, enough to get excited about – here’s something new: TimeSpans and DateTimes. A number of Microsoft Lync Server 2010 property values are stored using the TimeSpan data format; this format is typically used to tell you how much time you (or the system) should wait before carrying out a specified activity. For example, the Address Book Server has a property value with the TimeSpan data type: SynchronizePollingInterval. This property has a minimum value of 5 seconds and a maximum value of 3 hours.

Note. In case you’re wondering, SynchronizePollingInterval indicates how often the server checks to ensure that the user information in files is in synch with the user information in Active Directory.

So what’s wrong with TimeSpans? Nothing. You just need to know how to format a time span, in case you ever need to change a property value like SynchronizePollingInterval.

OK, so then how do you change a TimeSpan property value? Well, time spans use this format:

 
Days.Hours:Minutes:Seconds

In other words, to specify a synchronize polling interval of 90 minutes you’d use this value:

01:30:00

And how is that interpreted? You got it: 1 hour plus 30 minutes plus 0 seconds. Add that together and you get 90 minutes: one and a half hours.

Hmmm, this is easier than we thought it would be.

With that in mind, how could we change the global Address Book Server configuration in order to set the SynchroniziePollingInterval to 45 minutes? This is how:

Set-CsAddressBookConfiguration -SynchronizePollingInterval 00:45:00

Or, again, 0 hours plus 45 minutes plus 0 seconds.

That’s all there is to it. If you want to specify a time in days (note that TimeSpan properties tend to have minimum and maximum values, and many properties don’t allow you to set a time span measured in days) use this format:

20.12:00:00

As you can see, we specify the number of days, tack on a period, then include the rest of the time span. In the example above, the time span is set for 20 days and 12 hours that is, 20 days.12 hours:0 minutes:0 seconds.

Now, what about DateTime values? DateTime values are typically used to specify the time of day when you want an operation to run. The Address Book Server has an example of this data type, too: RunTimeOfDay. The property indicates the time of day that the servers generate a new Address Book file. DateTime properties store the time of day in this format, which is based on a 24-hour clock (sometimes referred to as military time):

Hours:Minutes

For example, 8:30 PM is 20 hours and 30 minutes; thus 8:30 PM would be expressed like this:

20:30

So how would you set the global Address Book server configuration so that the files are generated at 8:30 PM? Here’s how:

Set-CsAddressBookConfiguration –RunTimeOfDay 20:30

See, that wasn’t so bad, was it?

Incidentally, if you’re running the US-English version of Windows PowerShell you can also specify time values using a 12-hour clock:

Set-CsAddressBookConfiguration –RunTimeOfDay "8:30 PM"

However, at the moment we can’t guarantee that this format will work with each and every datetime property. You’ll just have to try and see what happens. Worst case scenario: the command will fail, and you’ll have to try again using the 24-hour clock format.