using System;
using System.Collections.Generic;
using System.Text;
using FormulaEditor.Interfaces;
namespace FormulaEditor
{
/// <summary>
/// Symbol of date time
/// </summary>
public class DateTimeSymbol : SimpleSymbol, IObjectOperation, IOperationAcceptor, IOperationDetector
{
protected DateTime dt;
static public readonly DateTimeSymbol Object = new DateTimeSymbol();
public DateTimeSymbol()
: base('d', 0, false, true, "Date Time")
{
}
public override object Clone()
{
DateTimeSymbol sym = new DateTimeSymbol();
sym.dt = dt;
return sym;
}
public DateTimeSymbol(DateTimeSymbol s)
: base(s)
{
dt = s.dt;
}
public override string ToString()
{
string ms = dt.Millisecond + "";
string ss = "";
for (int i = 0; i < 3 - ms.Length; i++)
{
ss += "0";
}
return dt.ToLongDateString() + " " + dt.ToLongTimeString() + MathSymbol.DecimalSep + ss + ms;
}
/// <summary>
/// Date time
/// </summary>
public DateTime DateTime
{
set
{
dt = value;
}
}
#region IObjectOperation Members
int IObjectOperation.Arity
{
get { return 0; }
}
object IObjectOperation.this[object[] x]
{
get { return dt; }
}
object IObjectOperation.ReturnType
{
get { return Object; }
}
bool IObjectOperation.IsPowered
{
get { return false; }
}
#endregion
#region IOperationAcceptor Members
IObjectOperation IOperationAcceptor.Accept(object type)
{
return this;
}
#endregion
#region IOperationDetector Members
IOperationAcceptor IOperationDetector.Detect(MathSymbol s)
{
if (s is DateTimeSymbol)
{
DateTimeSymbol dt = s as DateTimeSymbol;
return dt;
}
return null;
}
#endregion
}
}