#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab 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 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab 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 HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Globalization;
using HEAL.Attic;
namespace HeuristicLab.DataImporter.Data.Model {
[StorableType("7C0A4BD8-45A1-4710-AC42-1BCBB4DF03D5")]
public class DateTimeColumn : ColumnBase {
[Storable]
private List values;
[StorableConstructor]
protected DateTimeColumn(StorableConstructorFlag _) : base(_) { }
public DateTimeColumn(string columnName)
: base(columnName) {
this.values = new List();
}
public DateTimeColumn(string columnName, int capacity)
: this(columnName) {
this.values.Capacity = capacity;
}
public override Type DataType {
get { return typeof(DateTime?); }
}
public override string ToString() {
return base.ToString() + " ";
}
protected override System.Collections.IList Values {
get { return this.values; }
}
public override void AddValue(IComparable value) {
this.values.Add((DateTime?)value);
}
public override void AddValueOrNull(IComparable value) {
this.values.Add(ConvertToDateTime(value));
}
public override void ChangeValue(int position, IComparable value) {
this.values[position] = (DateTime?)value;
}
public override void ChangeValueOrNull(int position, IComparable value) {
this.values[position] = ConvertToDateTime(value);
}
public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
if (value == null)
this.values[position] = null;
else {
DateTime? val = ConvertToDateTime(value);
if (val != null)
this.values[position] = val;
}
}
public override void InsertValue(int position, IComparable value) {
this.values.Insert(position, (DateTime?)value);
}
private DateTime? ConvertToDateTime(IComparable value) {
DateTime val;
if (value == null)
return null;
if (DateTime.TryParse(value.ToString(), out val))
return val;
if (DateTime.TryParseExact(value.ToString(), "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out val))
return val;
return null;
}
public override ColumnBase CreateCopyOfColumnWithoutValues() {
return CreateCopyOfColumnWithoutValues(this.values.Capacity);
}
public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
return new DateTimeColumn(this.Name, capacity);
}
}
}