CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
SmartDate.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="SmartDate.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Provides a date data type that understands the concept</summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla.Properties;
11
12namespace Csla
13{
14
23 [Serializable()]
24#if !NETFX_CORE
25 [System.ComponentModel.TypeConverter(typeof(Csla.Core.TypeConverters.SmartDateConverter))]
26#endif
27 public struct SmartDate : Csla.Core.ISmartField,
28#if !NETFX_CORE
29 IConvertible,
30#endif
31 IComparable, IFormattable, IMobileObject
32 {
33 private DateTime _date;
34 private bool _initialized;
35 private EmptyValue _emptyValue;
36 private string _format;
37 private static string _defaultFormat;
38
39#if !NETFX_CORE
40 [NonSerialized]
41#endif
42 [NotUndoable]
43 private static Func<string, DateTime?> _customParser;
44
45#region EmptyValue enum
46
51 public enum EmptyValue
52 {
57 MinDate,
62 MaxDate
63 }
64
65#endregion
66
67#region Constructors
68
69 static SmartDate()
70 {
71 _defaultFormat = "d";
72 }
73
78 public SmartDate(bool emptyIsMin)
79 {
80 _emptyValue = GetEmptyValue(emptyIsMin);
81 _format = null;
82 _initialized = false;
83 // provide a dummy value to allow real initialization
84 _date = DateTime.MinValue;
85 SetEmptyDate(_emptyValue);
86 }
87
92 public SmartDate(EmptyValue emptyValue)
93 {
94 _emptyValue = emptyValue;
95 _format = null;
96 _initialized = false;
97 // provide a dummy value to allow real initialization
98 _date = DateTime.MinValue;
99 SetEmptyDate(_emptyValue);
100 }
101
110 public SmartDate(DateTime value)
111 {
112 _emptyValue = Csla.SmartDate.EmptyValue.MinDate;
113 _format = null;
114 _initialized = false;
115 _date = DateTime.MinValue;
116 Date = value;
117 }
118
124 public SmartDate(DateTime value, bool emptyIsMin)
125 {
126 _emptyValue = GetEmptyValue(emptyIsMin);
127 _format = null;
128 _initialized = false;
129 _date = DateTime.MinValue;
130 Date = value;
131 }
132
138 public SmartDate(DateTime value, EmptyValue emptyValue)
139 {
140 _emptyValue = emptyValue;
141 _format = null;
142 _initialized = false;
143 _date = DateTime.MinValue;
144 Date = value;
145 }
146
153 public SmartDate(DateTime value, EmptyValue emptyValue, DateTimeKind kind)
154 {
155 _emptyValue = emptyValue;
156 _format = null;
157 _initialized = false;
158 _date = DateTime.MinValue;
159 Date = DateTime.SpecifyKind(value, kind);
160 }
161
170 public SmartDate(DateTime? value)
171 {
172 _emptyValue = Csla.SmartDate.EmptyValue.MinDate;
173 _format = null;
174 _initialized = false;
175 _date = DateTime.MinValue;
176 if (value.HasValue)
177 Date = value.Value;
178 }
179
185 public SmartDate(DateTime? value, bool emptyIsMin)
186 {
187 _emptyValue = GetEmptyValue(emptyIsMin);
188 _format = null;
189 _initialized = false;
190 _date = DateTime.MinValue;
191 if (value.HasValue)
192 Date = value.Value;
193 }
194
200 public SmartDate(DateTime? value, EmptyValue emptyValue)
201 {
202 _emptyValue = emptyValue;
203 _format = null;
204 _initialized = false;
205 _date = DateTime.MinValue;
206 if (value.HasValue)
207 Date = value.Value;
208 }
209
226 public SmartDate(DateTimeOffset value)
227 {
228 _emptyValue = Csla.SmartDate.EmptyValue.MinDate;
229 _format = null;
230 _initialized = false;
231 _date = DateTime.MinValue;
232 Date = value.DateTime;
233 }
234
247 public SmartDate(DateTimeOffset value, bool emptyIsMin)
248 {
249 _emptyValue = GetEmptyValue(emptyIsMin);
250 _format = null;
251 _initialized = false;
252 _date = DateTime.MinValue;
253 Date = value.DateTime;
254 }
255
268 public SmartDate(DateTimeOffset value, EmptyValue emptyValue)
269 {
270 _emptyValue = emptyValue;
271 _format = null;
272 _initialized = false;
273 _date = DateTime.MinValue;
274 Date = value.DateTime;
275 }
276
285 public SmartDate(string value)
286 {
287 _emptyValue = EmptyValue.MinDate;
288 _format = null;
289 _initialized = true;
290 _date = DateTime.MinValue;
291 this.Text = value;
292 }
293
299 public SmartDate(string value, bool emptyIsMin)
300 {
301 _emptyValue = GetEmptyValue(emptyIsMin);
302 _format = null;
303 _initialized = true;
304 _date = DateTime.MinValue;
305 this.Text = value;
306 }
307
313 public SmartDate(string value, EmptyValue emptyValue)
314 {
315 _emptyValue = emptyValue;
316 _format = null;
317 _initialized = true;
318 _date = DateTime.MinValue;
319 this.Text = value;
320 }
321
322 private static EmptyValue GetEmptyValue(bool emptyIsMin)
323 {
324 if (emptyIsMin)
325 return EmptyValue.MinDate;
326 else
327 return EmptyValue.MaxDate;
328 }
329
330 private void SetEmptyDate(EmptyValue emptyValue)
331 {
332 if (emptyValue == SmartDate.EmptyValue.MinDate)
333 this.Date = DateTime.MinValue;
334 else
335 this.Date = DateTime.MaxValue;
336 }
337
338#endregion
339
340#region Text Support
341
356 public static void SetDefaultFormatString(string formatString)
357 {
358 _defaultFormat = formatString;
359 }
360
370 public string FormatString
371 {
372 get
373 {
374 if (_format == null)
375 _format = _defaultFormat;
376 return _format;
377 }
378 set
379 {
380 _format = value;
381 }
382 }
383
399 public string Text
400 {
401 get { return DateToString(this.Date, FormatString, _emptyValue); }
402 set { this.Date = StringToDate(value, _emptyValue); }
403 }
404
405#endregion
406
407#region Date Support
408
413 {
414 get
415 {
416 if (!_initialized)
417 {
418 _date = _emptyValue == SmartDate.EmptyValue.MinDate ? DateTime.MinValue : DateTime.MaxValue;
419 _initialized = true;
420 }
421 return _date;
422 }
423 set
424 {
425 _date = value;
426 _initialized = true;
427 }
428 }
429
434 {
435 return new DateTimeOffset(this.Date);
436 }
437
442 {
443 if (this.IsEmpty)
444 return new DateTime?();
445 else
446 return new DateTime?(this.Date);
447 }
448
449#endregion
450
451#region System.Object overrides
452
456 public override string ToString()
457 {
458 return this.Text;
459 }
460
467 public string ToString(string format)
468 {
469 if (string.IsNullOrEmpty(format))
470 return this.ToString();
471 else
472 return DateToString(this.Date, format, _emptyValue);
473 }
474
480 public override bool Equals(object obj)
481 {
482 if (obj is SmartDate)
483 {
484 SmartDate tmp = (SmartDate)obj;
485 if (this.IsEmpty && tmp.IsEmpty)
486 return true;
487 else
488 return this.Date.Equals(tmp.Date);
489 }
490 else if (obj is DateTime)
491 return this.Date.Equals((DateTime)obj);
492 else if (obj is string)
493 return (this.CompareTo(obj.ToString()) == 0);
494 else
495 return false;
496 }
497
501 public override int GetHashCode()
502 {
503 return this.Date.GetHashCode();
504 }
505
506#endregion
507
508#region DBValue
509
510#if !NETFX_CORE
528 public object DBValue
529 {
530 get
531 {
532 if (this.IsEmpty)
533 return DBNull.Value;
534 else
535 return this.Date;
536 }
537 }
538#endif
539
540#endregion
541
542#region Empty Dates
543
547 public bool IsEmpty
548 {
549 get
550 {
551 if (_emptyValue == EmptyValue.MinDate)
552 return this.Date.Equals(DateTime.MinValue);
553 else
554 return this.Date.Equals(DateTime.MaxValue);
555 }
556 }
557
567 public bool EmptyIsMin
568 {
569 get { return (_emptyValue == EmptyValue.MinDate); }
570 }
571
572#endregion
573
574#region Conversion Functions
575
585 public static Func<string, DateTime?> CustomParser
586 {
587 get { return _customParser; }
588 set { _customParser = value; }
589 }
590
591
600 public static SmartDate Parse(string value)
601 {
602 return new SmartDate(value);
603 }
604
611 public static SmartDate Parse(string value, EmptyValue emptyValue)
612 {
613 return new SmartDate(value, emptyValue);
614 }
615
622 public static SmartDate Parse(string value, bool emptyIsMin)
623 {
624 return new SmartDate(value, emptyIsMin);
625 }
626
633 public static bool TryParse(string value, ref SmartDate result)
634 {
635 return TryParse(value, EmptyValue.MinDate, ref result);
636 }
637
645 public static bool TryParse(string value, EmptyValue emptyValue, ref SmartDate result)
646 {
647 System.DateTime dateResult = DateTime.MinValue;
648 if (TryStringToDate(value, emptyValue, ref dateResult))
649 {
650 result = new SmartDate(dateResult, emptyValue);
651 return true;
652 }
653 else
654 {
655 return false;
656 }
657 }
658
668 public static DateTime StringToDate(string value)
669 {
670 return StringToDate(value, true);
671 }
672
684 public static DateTime StringToDate(string value, bool emptyIsMin)
685 {
686 return StringToDate(value, GetEmptyValue(emptyIsMin));
687 }
688
700 public static DateTime StringToDate(string value, EmptyValue emptyValue)
701 {
702 DateTime result = DateTime.MinValue;
703 if (TryStringToDate(value, emptyValue, ref result))
704 return result;
705 else
706 throw new ArgumentException(Resources.StringToDateException);
707 }
708
709 private static bool TryStringToDate(string value, EmptyValue emptyValue, ref DateTime result)
710 {
711
712 DateTime tmp;
713
714 // call custom parser if set...
715 if (_customParser != null)
716 {
717 var tmpValue = _customParser.Invoke(value);
718 // i f custom parser returned a value then parsing succeeded
719 if (tmpValue.HasValue)
720 {
721 result = tmpValue.Value;
722 return true;
723 }
724 }
725
726 if (String.IsNullOrEmpty(value))
727 {
728 result = emptyValue == EmptyValue.MinDate ? DateTime.MinValue : DateTime.MaxValue;
729 return true;
730 }
731 if (DateTime.TryParse(value, out tmp))
732 {
733 result = tmp;
734 return true;
735 }
736
737 string ldate = value.Trim().ToLower();
738 if (ldate == Resources.SmartDateT ||
739 ldate == Resources.SmartDateToday ||
740 ldate == ".")
741 {
742 result = DateTime.Now;
743 return true;
744 }
745 if (ldate == Resources.SmartDateY ||
746 ldate == Resources.SmartDateYesterday ||
747 ldate == "-")
748 {
749 result = DateTime.Now.AddDays(-1);
750 return true;
751 }
752 if (ldate == Resources.SmartDateTom ||
753 ldate == Resources.SmartDateTomorrow ||
754 ldate == "+")
755 {
756 result = DateTime.Now.AddDays(1);
757 return true;
758 }
759
760 return false;
761 }
762
775 public static string DateToString(
776 DateTime value, string formatString)
777 {
778 return DateToString(value, formatString, true);
779 }
780
794 public static string DateToString(
795 DateTime value, string formatString, bool emptyIsMin)
796 {
797 return DateToString(value, formatString, GetEmptyValue(emptyIsMin));
798 }
799
813 public static string DateToString(
814 DateTime value, string formatString, EmptyValue emptyValue)
815 {
816 if (emptyValue == EmptyValue.MinDate)
817 {
818 if (value == DateTime.MinValue)
819 return string.Empty;
820 }
821 else
822 {
823 if (value == DateTime.MaxValue)
824 return string.Empty;
825 }
826 return string.Format("{0:" + formatString + "}", value);
827 }
828
829#endregion
830
831#region Manipulation Functions
832
843 public int CompareTo(SmartDate value)
844 {
845 if (this.IsEmpty && value.IsEmpty)
846 return 0;
847 else
848 return _date.CompareTo(value.Date);
849 }
850
861 int IComparable.CompareTo(object value)
862 {
863 if (value is SmartDate)
864 return CompareTo((SmartDate)value);
865 else
866 throw new ArgumentException(Resources.ValueNotSmartDateException);
867 }
868
874 public int CompareTo(string value)
875 {
876 return this.Date.CompareTo(StringToDate(value, _emptyValue));
877 }
878
891 public int CompareTo(DateTimeOffset value)
892 {
893 return this.Date.CompareTo(value.DateTime);
894 }
895
901 public int CompareTo(DateTime value)
902 {
903 return this.Date.CompareTo(value);
904 }
905
910 public DateTime Add(TimeSpan value)
911 {
912 if (IsEmpty)
913 return this.Date;
914 else
915 return this.Date.Add(value);
916 }
917
922 public DateTime Subtract(TimeSpan value)
923 {
924 if (IsEmpty)
925 return this.Date;
926 else
927 return this.Date.Subtract(value);
928 }
929
941 public TimeSpan Subtract(DateTimeOffset value)
942 {
943 if (IsEmpty)
944 return TimeSpan.Zero;
945 else
946 return this.Date.Subtract(value.DateTime);
947 }
948
953 public TimeSpan Subtract(DateTime value)
954 {
955 if (IsEmpty)
956 return TimeSpan.Zero;
957 else
958 return this.Date.Subtract(value);
959 }
960
961#endregion
962
963#region Operators
964
971 public static bool operator ==(SmartDate obj1, SmartDate obj2)
972 {
973 return obj1.Equals(obj2);
974 }
975
982 public static bool operator !=(SmartDate obj1, SmartDate obj2)
983 {
984 return !obj1.Equals(obj2);
985 }
986
991 public static implicit operator string(SmartDate obj1)
992 {
993 return obj1.Text;
994 }
995
1000 public static implicit operator System.DateTime(SmartDate obj1)
1001 {
1002 return obj1.Date;
1003 }
1004
1009 public static implicit operator System.DateTime?(SmartDate obj1)
1010 {
1011 return obj1.ToNullableDate();
1012 }
1013
1018 public static implicit operator DateTimeOffset(SmartDate obj1)
1019 {
1020 return obj1.ToDateTimeOffset();
1021 }
1022
1027 public static explicit operator SmartDate(string dateValue)
1028 {
1029 return new SmartDate(dateValue);
1030 }
1031
1036 public static implicit operator SmartDate(System.DateTime dateValue)
1037 {
1038 return new SmartDate(dateValue);
1039 }
1040
1045 public static implicit operator SmartDate(System.DateTime? dateValue)
1046 {
1047 return new SmartDate(dateValue);
1048 }
1049
1054 public static explicit operator SmartDate(DateTimeOffset dateValue)
1055 {
1056 return new SmartDate(dateValue);
1057 }
1058
1065 public static bool operator ==(SmartDate obj1, DateTime obj2)
1066 {
1067 return obj1.Equals(obj2);
1068 }
1069
1076 public static bool operator !=(SmartDate obj1, DateTime obj2)
1077 {
1078 return !obj1.Equals(obj2);
1079 }
1080
1087 public static bool operator ==(SmartDate obj1, string obj2)
1088 {
1089 return obj1.Equals(obj2);
1090 }
1091
1098 public static bool operator !=(SmartDate obj1, string obj2)
1099 {
1100 return !obj1.Equals(obj2);
1101 }
1102
1109 public static SmartDate operator +(SmartDate start, TimeSpan span)
1110 {
1111 return new SmartDate(start.Add(span), start.EmptyIsMin);
1112 }
1113
1120 public static SmartDate operator -(SmartDate start, TimeSpan span)
1121 {
1122 return new SmartDate(start.Subtract(span), start.EmptyIsMin);
1123 }
1124
1131 public static TimeSpan operator -(SmartDate start, SmartDate finish)
1132 {
1133 return start.Subtract(finish.Date);
1134 }
1135
1142 public static bool operator >(SmartDate obj1, SmartDate obj2)
1143 {
1144 return obj1.CompareTo(obj2) > 0;
1145 }
1146
1153 public static bool operator <(SmartDate obj1, SmartDate obj2)
1154 {
1155 return obj1.CompareTo(obj2) < 0;
1156 }
1157
1164 public static bool operator >(SmartDate obj1, DateTime obj2)
1165 {
1166 return obj1.CompareTo(obj2) > 0;
1167 }
1168
1175 public static bool operator <(SmartDate obj1, DateTime obj2)
1176 {
1177 return obj1.CompareTo(obj2) < 0;
1178 }
1179
1186 public static bool operator >(SmartDate obj1, string obj2)
1187 {
1188 return obj1.CompareTo(obj2) > 0;
1189 }
1190
1197 public static bool operator <(SmartDate obj1, string obj2)
1198 {
1199 return obj1.CompareTo(obj2) < 0;
1200 }
1201
1208 public static bool operator >=(SmartDate obj1, SmartDate obj2)
1209 {
1210 return obj1.CompareTo(obj2) >= 0;
1211 }
1212
1219 public static bool operator <=(SmartDate obj1, SmartDate obj2)
1220 {
1221 return obj1.CompareTo(obj2) <= 0;
1222 }
1223
1230 public static bool operator >=(SmartDate obj1, DateTime obj2)
1231 {
1232 return obj1.CompareTo(obj2) >= 0;
1233 }
1234
1241 public static bool operator <=(SmartDate obj1, DateTime obj2)
1242 {
1243 return obj1.CompareTo(obj2) <= 0;
1244 }
1245
1252 public static bool operator >=(SmartDate obj1, string obj2)
1253 {
1254 return obj1.CompareTo(obj2) >= 0;
1255 }
1256
1263 public static bool operator <=(SmartDate obj1, string obj2)
1264 {
1265 return obj1.CompareTo(obj2) <= 0;
1266 }
1267
1268#endregion
1269
1270#if !NETFX_CORE
1271#region IConvertible
1272
1273 System.TypeCode IConvertible.GetTypeCode()
1274 {
1275 return ((IConvertible)_date).GetTypeCode();
1276 }
1277
1278 bool IConvertible.ToBoolean(System.IFormatProvider provider)
1279 {
1280 return ((IConvertible)_date).ToBoolean(provider);
1281 }
1282
1283 byte IConvertible.ToByte(System.IFormatProvider provider)
1284 {
1285 return ((IConvertible)_date).ToByte(provider);
1286 }
1287
1288 char IConvertible.ToChar(System.IFormatProvider provider)
1289 {
1290 return ((IConvertible)_date).ToChar(provider);
1291 }
1292
1293 System.DateTime IConvertible.ToDateTime(System.IFormatProvider provider)
1294 {
1295 return ((IConvertible)_date).ToDateTime(provider);
1296 }
1297
1298 decimal IConvertible.ToDecimal(System.IFormatProvider provider)
1299 {
1300 return ((IConvertible)_date).ToDecimal(provider);
1301 }
1302
1303 double IConvertible.ToDouble(System.IFormatProvider provider)
1304 {
1305 return ((IConvertible)_date).ToDouble(provider);
1306 }
1307
1308 short IConvertible.ToInt16(System.IFormatProvider provider)
1309 {
1310 return ((IConvertible)_date).ToInt16(provider);
1311 }
1312
1313 int IConvertible.ToInt32(System.IFormatProvider provider)
1314 {
1315 return ((IConvertible)_date).ToInt32(provider);
1316 }
1317
1318 long IConvertible.ToInt64(System.IFormatProvider provider)
1319 {
1320 return ((IConvertible)_date).ToInt64(provider);
1321 }
1322
1323 sbyte IConvertible.ToSByte(System.IFormatProvider provider)
1324 {
1325 return ((IConvertible)_date).ToSByte(provider);
1326 }
1327
1328 float IConvertible.ToSingle(System.IFormatProvider provider)
1329 {
1330 return ((IConvertible)_date).ToSingle(provider);
1331 }
1332
1333 string IConvertible.ToString(System.IFormatProvider provider)
1334 {
1335 return ((IConvertible)Text).ToString(provider);
1336 }
1337
1338 object IConvertible.ToType(System.Type conversionType, System.IFormatProvider provider)
1339 {
1340 if (conversionType.Equals(typeof(string)))
1341 return ((IConvertible)Text).ToType(conversionType, provider);
1342 else if (conversionType.Equals(typeof(SmartDate)))
1343 return this;
1344 else
1345 return ((IConvertible)_date).ToType(conversionType, provider);
1346 }
1347
1348 ushort IConvertible.ToUInt16(System.IFormatProvider provider)
1349 {
1350 return ((IConvertible)_date).ToUInt16(provider);
1351 }
1352
1353 uint IConvertible.ToUInt32(System.IFormatProvider provider)
1354 {
1355 return ((IConvertible)_date).ToUInt32(provider);
1356 }
1357
1358 ulong IConvertible.ToUInt64(System.IFormatProvider provider)
1359 {
1360 return ((IConvertible)_date).ToUInt64(provider);
1361 }
1362
1363#endregion
1364
1365#endif
1366
1367#region IFormattable Members
1368
1369 string IFormattable.ToString(string format, IFormatProvider formatProvider)
1370 {
1371 return this.ToString(format);
1372 }
1373
1374#endregion
1375
1376#region IMobileObject Members
1377
1379 {
1380 info.AddValue("SmartDate._date", _date);
1381 info.AddValue("SmartDate._defaultFormat", _defaultFormat);
1382 info.AddValue("SmartDate._emptyValue", _emptyValue.ToString());
1383 info.AddValue("SmartDate._initialized", _initialized);
1384 info.AddValue("SmartDate._format", _format);
1385 }
1386
1388 {
1389 _date = info.GetValue<DateTime>("SmartDate._date");
1390 _defaultFormat = info.GetValue<string>("SmartDate._defaultFormat");
1391 _emptyValue = (EmptyValue)System.Enum.Parse(typeof(EmptyValue), info.GetValue<string>("SmartDate._emptyValue"), true);
1392 _format = info.GetValue<string>("SmartDate._format");
1393 _initialized = info.GetValue<bool>("SmartDate._initialized");
1394 }
1395
1397 {
1398 //
1399 }
1400
1402 {
1403 //
1404 }
1405
1406#endregion
1407 }
1408}
Converts values to and from a SmartDate.
A strongly-typed resource class, for looking up localized strings, etc.
static string SmartDateToday
Looks up a localized string similar to today.
static string StringToDateException
Looks up a localized string similar to String value can not be converted to a date.
static string SmartDateYesterday
Looks up a localized string similar to yesterday.
static string SmartDateY
Looks up a localized string similar to y.
static string ValueNotSmartDateException
Looks up a localized string similar to Value is not a SmartDate.
static string SmartDateTom
Looks up a localized string similar to tom.
static string SmartDateTomorrow
Looks up a localized string similar to tomorrow.
static string SmartDateT
Looks up a localized string similar to t.
Serializes and deserializes objects at the field level.
Object containing the serialization data for a specific object.
void AddValue(string name, object value)
Adds a value to the serialization stream.
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...
void GetChildren(SerializationInfo info, MobileFormatter formatter)
Method called by MobileFormatter when an object should serialize its child references.
void GetState(SerializationInfo info)
Method called by MobileFormatter when an object should serialize its data.
void SetChildren(SerializationInfo info, MobileFormatter formatter)
Method called by MobileFormatter when an object should deserialize its child references.
void SetState(SerializationInfo info)
Method called by MobileFormatter when an object should be deserialized.
@ DateTimeOffset
Date/time plus time zone / DateTimeOffset
@ Serializable
Prevents updating or inserting until the transaction is complete.
Provides a date data type that understands the concept of an empty date value.
Definition: SmartDate.cs:32
static bool operator<(SmartDate obj1, SmartDate obj2)
Less than operator
Definition: SmartDate.cs:1153
static SmartDate Parse(string value, EmptyValue emptyValue)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:611
bool IsEmpty
Gets a value indicating whether this object contains an empty date.
Definition: SmartDate.cs:548
static bool operator<=(SmartDate obj1, SmartDate obj2)
Less than or equals operator
Definition: SmartDate.cs:1219
DateTime? ToNullableDate()
Gets the value as a DateTime?.
Definition: SmartDate.cs:441
static DateTime StringToDate(string value, EmptyValue emptyValue)
Converts a text date representation into a Date value.
Definition: SmartDate.cs:700
SmartDate(bool emptyIsMin)
Creates a new SmartDate object.
Definition: SmartDate.cs:78
static string DateToString(DateTime value, string formatString, EmptyValue emptyValue)
Converts a date value into a text representation.
Definition: SmartDate.cs:813
static DateTime StringToDate(string value, bool emptyIsMin)
Definition: SmartDate.cs:684
SmartDate(DateTime? value, bool emptyIsMin)
Creates a new SmartDate object.
Definition: SmartDate.cs:185
SmartDate(EmptyValue emptyValue)
Creates a new SmartDate object.
Definition: SmartDate.cs:92
SmartDate(DateTimeOffset value, bool emptyIsMin)
Creates a new SmartDate object.
Definition: SmartDate.cs:247
SmartDate(DateTimeOffset value, EmptyValue emptyValue)
Creates a new SmartDate object.
Definition: SmartDate.cs:268
EmptyValue
Indicates the empty value of a SmartDate.
Definition: SmartDate.cs:52
static SmartDate()
Definition: SmartDate.cs:69
DateTime? Date
Gets or sets the date value.
Definition: SmartDate.cs:413
static DateTime StringToDate(string value)
Converts a text date representation into a Date value.
Definition: SmartDate.cs:668
TimeSpan Subtract(DateTimeOffset value)
Subtracts a DateTimeOffset from the object.
Definition: SmartDate.cs:941
override string ToString()
Returns a text representation of the date value.
Definition: SmartDate.cs:456
int CompareTo(SmartDate value)
Compares one SmartDate to another.
Definition: SmartDate.cs:843
static bool operator>(SmartDate obj1, SmartDate obj2)
Greater than operator
Definition: SmartDate.cs:1142
DateTime Subtract(TimeSpan value)
Subtracts a TimeSpan from the object.
Definition: SmartDate.cs:922
DateTimeOffset ToDateTimeOffset()
Gets the value as a DateTimeOffset.
Definition: SmartDate.cs:433
override int GetHashCode()
Returns a hash code for this object.
Definition: SmartDate.cs:501
static SmartDate operator-(SmartDate start, TimeSpan span)
Subtraction operator
Definition: SmartDate.cs:1120
static bool TryParse(string value, ref SmartDate result)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:633
static SmartDate operator+(SmartDate start, TimeSpan span)
Addition operator
Definition: SmartDate.cs:1109
bool EmptyIsMin
Gets a value indicating whether an empty date is the min or max possible date value.
Definition: SmartDate.cs:568
int CompareTo(DateTime value)
Compares a SmartDate to a date value.
Definition: SmartDate.cs:901
static SmartDate Parse(string value, bool emptyIsMin)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:622
object DBValue
Gets a database-friendly version of the date value.
Definition: SmartDate.cs:529
string ToString(string format)
Returns a text representation of the date value.
Definition: SmartDate.cs:467
static bool TryParse(string value, EmptyValue emptyValue, ref SmartDate result)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:645
int CompareTo(string value)
Compares a SmartDate to a text date value.
Definition: SmartDate.cs:874
SmartDate(DateTime value, bool emptyIsMin)
Creates a new SmartDate object.
Definition: SmartDate.cs:124
SmartDate(string value)
Creates a new SmartDate object.
Definition: SmartDate.cs:285
int CompareTo(DateTimeOffset value)
Compares a SmartDate to a date value.
Definition: SmartDate.cs:891
SmartDate(DateTime? value)
Creates a new SmartDate object.
Definition: SmartDate.cs:170
SmartDate(DateTime value)
Creates a new SmartDate object.
Definition: SmartDate.cs:110
static SmartDate Parse(string value)
Converts a string value into a SmartDate.
Definition: SmartDate.cs:600
static string DateToString(DateTime value, string formatString)
Converts a date value into a text representation.
Definition: SmartDate.cs:775
string FormatString
Gets or sets the format string used to format a date value when it is returned as text.
Definition: SmartDate.cs:371
override bool Equals(object obj)
Compares this object to another SmartDate for equality.
Definition: SmartDate.cs:480
SmartDate(DateTime value, EmptyValue emptyValue)
Creates a new SmartDate object.
Definition: SmartDate.cs:138
SmartDate(string value, EmptyValue emptyValue)
Creates a new SmartDate object.
Definition: SmartDate.cs:313
SmartDate(DateTime value, EmptyValue emptyValue, DateTimeKind kind)
Creates a new SmartDate object.
Definition: SmartDate.cs:153
static void SetDefaultFormatString(string formatString)
Sets the global default format string used by all new SmartDate values going forward.
Definition: SmartDate.cs:356
string Text
Gets or sets the date value.
Definition: SmartDate.cs:400
SmartDate(DateTime? value, EmptyValue emptyValue)
Creates a new SmartDate object.
Definition: SmartDate.cs:200
static bool operator!=(SmartDate obj1, SmartDate obj2)
Inequality operator
Definition: SmartDate.cs:982
static bool operator>=(SmartDate obj1, SmartDate obj2)
Greater than or equals operator
Definition: SmartDate.cs:1208
TimeSpan Subtract(DateTime value)
Subtracts a DateTime from the object.
Definition: SmartDate.cs:953
DateTime Add(TimeSpan value)
Adds a TimeSpan onto the object.
Definition: SmartDate.cs:910
SmartDate(string value, bool emptyIsMin)
Creates a new SmartDate object.
Definition: SmartDate.cs:299
SmartDate(DateTimeOffset value)
Creates a new SmartDate object.
Definition: SmartDate.cs:226
static Func< string, DateTime?> CustomParser
Gets or sets the custom parser.
Definition: SmartDate.cs:586
static bool operator==(SmartDate obj1, SmartDate obj2)
Equality operator
Definition: SmartDate.cs:971
static string DateToString(DateTime value, string formatString, bool emptyIsMin)
Converts a date value into a text representation.
Definition: SmartDate.cs:794