[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Condor-users] CurrentTime = ?



On 5/31/07, Jones, Torrin A (US SSA) <torrin.jones@xxxxxxxxxxxxxx> wrote:
True.  I didn't say that correctly.  What I meant to say was I needed to
set an expression like this . . .

PeriodicRelease     = (CurrentTime > 1180116476)

So I needed to figure out how the calculate the difference between the
execute time and epoch in seconds.  I figured out exactly how to do it
with lots of trial and error.

For people who need to do this "Unix Epoch Time" in google is your friend

www.thescripts.com has several explanations about how to calculate it
in things like c# and java. Perl has support for it built in.

here is my (hacked into a satic method) C# code for it:

Note that is does some sanity checking to avoid accidentally parsing
some reasonable valued int field as a DateTime. You may not want this

static readonly DateTime UnixEpochStartTime = new
DateTime(1970,1,1,0,0,0,DateTimeKind.Utc);

/// <summary>
/// helper method to get the attribute value as a DateTime based on
the field being one of condor's unix epoch fields
/// </summary>
/// <param name="name">name of the attribute</param>
/// <param name="name">value of the attribute</param>
/// <returns>the value as a DateTime (in utc time) or throws an
exception</returns>
public static DateTime ParseDateTimeAttribute(string name, string value)
{
   if (value == null)
   {
	throw new ArgumentNullException("The specified attribute has a null
value", name);
   }
   else
   {
	int secondsFromEpoch;
	try
	{
	    secondsFromEpoch = int.Parse(value);
	}
	catch (FormatException e)
	{
	    throw new CondorClassAdException("The specified attribute value
'"+ value +"' could not be parsed as an int", name, e);
	}
	catch (OverflowException e)
	{
	    throw new CondorClassAdException("The specified attribute value
'"+ value +"' is too big for an int", name, e);
	}
   }

   if (secondsFromEpoch <= 1104492410) // no way should we be getting
times before 2005!
   {
	throw new ArgumentException(string.Format(
	    "The specified attribute '{0}' has a value of '{1}' which would
convert to a datetime on or before {2:yyyy/MM/dd HH:mm:ss}",
	    name, secondsFromEpoch, UnixEpochStartTime.AddYears(35)), name);
   }
   return UnixEpochStartTime.AddSeconds(secondsFromEpoch);
}