// NAnt - A .NET build tool
// Copyright (C) 2001-2003 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Gert Driesen (gert.driesen@ardatis.com)
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Reflection;
using NAnt.Core;
using NAnt.Core.Types;
using NAnt.Core.Attributes;
namespace NAnt.Core.Functions {
[FunctionSet("timespan", "Date/Time")]
public class TimeSpanFunctions : FunctionSetBase {
#region Public Instance Constructors
public TimeSpanFunctions(Project project, PropertyDictionary properties) : base(project, properties) {
}
#endregion Public Instance Constructors
#region Public Static Methods
///
/// Returns the total number of days represented by the specified
/// , expressed in whole and fractional days.
///
/// A .
///
/// The total number of days represented by the given .
///
[Function("get-total-days")]
public static double GetTotalDays(TimeSpan value) {
return value.TotalDays;
}
///
/// Returns the total number of hours represented by the specified
/// , expressed in whole and fractional hours.
///
/// A .
///
/// The total number of hours represented by the given .
///
[Function("get-total-hours")]
public static double GetTotalHours(TimeSpan value) {
return value.TotalHours;
}
///
/// Returns the total number of minutes represented by the specified
/// , expressed in whole and fractional minutes.
///
/// A .
///
/// The total number of minutes represented by the given .
///
[Function("get-total-minutes")]
public static double GetTotalMinutes(TimeSpan value) {
return value.TotalMinutes;
}
///
/// Returns the total number of seconds represented by the specified
/// , expressed in whole and fractional seconds.
///
/// A .
///
/// The total number of seconds represented by the given .
///
[Function("get-total-seconds")]
public static double GetTotalSeconds(TimeSpan value) {
return value.TotalSeconds;
}
///
/// Returns the total number of milliseconds represented by the specified
/// , expressed in whole and fractional milliseconds.
///
/// A .
///
/// The total number of milliseconds represented by the given
/// .
///
[Function("get-total-milliseconds")]
public static double GetTotalMilliseconds(TimeSpan value) {
return value.TotalMilliseconds;
}
///
/// Returns the number of whole days represented by the specified
/// .
///
/// A .
///
/// The number of whole days represented by the given
/// .
///
///
///
/// Remove all files that have not been modified in the last 7 days from directory "binaries".
///
///
///
///
///
///
/// ]]>
///
///
[Function("get-days")]
public static int GetDays(TimeSpan value) {
return value.Days;
}
///
/// Returns the number of whole hours represented by the specified
/// .
///
/// A .
///
/// The number of whole hours represented by the given
/// .
///
[Function("get-hours")]
public static int GetHours(TimeSpan value) {
return value.Hours;
}
///
/// Returns the number of whole minutes represented by the specified
/// .
///
/// A .
///
/// The number of whole minutes represented by the given
/// .
///
[Function("get-minutes")]
public static int GetMinutes(TimeSpan value) {
return value.Minutes;
}
///
/// Returns the number of whole seconds represented by the specified
/// .
///
/// A .
///
/// The number of whole seconds represented by the given
/// .
///
[Function("get-seconds")]
public static int GetSeconds(TimeSpan value) {
return value.Seconds;
}
///
/// Returns the number of whole milliseconds represented by the specified
/// .
///
/// A .
///
/// The number of whole milliseconds represented by the given
/// .
///
[Function("get-milliseconds")]
public static int GetMilliseconds(TimeSpan value) {
return value.Milliseconds;
}
///
/// Returns the number of ticks contained in the specified
/// .
///
/// A .
///
/// The number of ticks contained in the given .
///
[Function("get-ticks")]
public static long GetTicks(TimeSpan value) {
return value.Ticks;
}
///
/// Returns a that represents a specified number
/// of days, where the specification is accurate to the nearest millisecond.
///
/// A number of days, accurate to the nearest millisecond.
///
/// A that represents .
///
[Function("from-days")]
public static TimeSpan FromDays(double value) {
return TimeSpan.FromDays(value);
}
///
/// Returns a that represents a specified number
/// of hours, where the specification is accurate to the nearest
/// millisecond.
///
/// A number of hours, accurate to the nearest millisecond.
///
/// A that represents .
///
[Function("from-hours")]
public static TimeSpan FromHours(double value) {
return TimeSpan.FromHours(value);
}
///
/// Returns a that represents a specified number
/// of minutes, where the specification is accurate to the nearest
/// millisecond.
///
/// A number of minutes, accurate to the nearest millisecond.
///
/// A that represents .
///
[Function("from-minutes")]
public static TimeSpan FromMinutes(double value) {
return TimeSpan.FromMinutes(value);
}
///
/// Returns a that represents a specified number
/// of seconds, where the specification is accurate to the nearest
/// millisecond.
///
/// A number of seconds, accurate to the nearest millisecond.
///
/// A that represents .
///
[Function("from-seconds")]
public static TimeSpan FromSeconds(double value) {
return TimeSpan.FromSeconds(value);
}
///
/// Returns a that represents a specified number
/// of milliseconds.
///
/// A number of milliseconds.
///
/// A that represents .
///
[Function("from-milliseconds")]
public static TimeSpan FromMilliseconds(double value) {
return TimeSpan.FromMilliseconds(value);
}
///
/// Returns a that represents a specified time,
/// where the specification is in units of ticks.
///
/// A number of ticks that represent a time.
///
/// A that represents .
///
[Function("from-ticks")]
public static TimeSpan FromTicks(long value) {
return TimeSpan.FromTicks(value);
}
#endregion Public Static Methods
}
[FunctionSet("timespan", "Conversion")]
public class TimeSpanConversionFunctions : FunctionSetBase {
#region Public Instance Constructors
public TimeSpanConversionFunctions(Project project, PropertyDictionary properties) : base(project, properties) {
}
#endregion Public Instance Constructors
#region Public Static Methods
///
/// Constructs a from a time indicated by a
/// specified string.
///
/// A string.
///
/// A that corresponds to .
///
/// has an invalid format.
/// At least one of the hours, minutes, or seconds components is outside its valid range.
[Function("parse")]
public static TimeSpan Parse(string s) {
return TimeSpan.Parse(s);
}
///
/// Converts the specified to its equivalent
/// string representation.
///
/// A to convert.
///
/// The string representation of . The format
/// of the return value is of the form: [-][d.]hh:mm:ss[.ff].
///
[Function("to-string")]
public static string ToString(TimeSpan value) {
return value.ToString();
}
#endregion Public Static Methods
}
}