unit Myc.Data.Types.Timestamp;

interface

uses
    System.SysUtils,
    Myc.Data.Types;

type
    TImplDataTimestampType = class(TInterfacedObject, IDataType, IDataTimestampType)
    strict private
        class var
            FSingleton: IDataTimestampType;
        class constructor CreateClass;
    public
        function GetName: String;
        function GetKind: TDataKind;
        function CreateValue(const AValue: TDateTime): IDataTimestampValue;
        class property Singleton: IDataTimestampType read FSingleton;
    end;

implementation

type
    TImplDataTimestampValue = class(TInterfacedObject, IDataValue, IDataTimestampValue)
    private
        FValue: TDateTime;
        function GetDataType: IDataType;
        function GetAsString: string;
        function GetValue: TDateTime;
    public
        constructor Create(const AValue: TDateTime);
    end;

{ TImplDataTimestampType }

class constructor TImplDataTimestampType.CreateClass;
begin
    FSingleton := TImplDataTimestampType.Create;
end;

function TImplDataTimestampType.CreateValue(const AValue: TDateTime): IDataTimestampValue;
begin
    Result := TImplDataTimestampValue.Create(AValue);
end;

function TImplDataTimestampType.GetName: String;
begin
    Result := 'Timestamp';
end;

function TImplDataTimestampType.GetKind: TDataKind;
begin
    Result := dkTimestamp;
end;

{ TImplDataTimestampValue }

constructor TImplDataTimestampValue.Create(const AValue: TDateTime);
begin
    inherited Create;
    FValue := AValue;
end;

function TImplDataTimestampValue.GetDataType: IDataType;
begin
    Result := TImplDataTimestampType.Singleton;
end;

function TImplDataTimestampValue.GetAsString: string;
begin
    Result := DateTimeToStr(FValue);
end;

function TImplDataTimestampValue.GetValue: TDateTime;
begin
    Result := FValue;
end;

end.
