Created
April 25, 2017 20:44
-
-
Save ortuagustin/f5fa2e0676841061424e75e99c58df91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit DateTimeHelper.Exceptions; | |
interface | |
uses | |
System.SysUtils; | |
type | |
{$REGION 'Exceptions'} | |
/// <summary> Ancestro base para todas las excepciones elevadas por TDateTimeHelper </summary> | |
EDateTimeError = class abstract(Exception); | |
/// <summary> Elevada cuando se intenta crear una instancia invalida de TDateTime, es decir, una fecha imposible </summary> | |
EIllegalDateTime = class(EDateTimeError); | |
/// <summary> Elevada cuando se intenta crear una instancia de TDateTime a partir de un string invalido </summary> | |
ECannotParseDateTime = class(EDateTimeError); | |
{$ENDREGION} | |
{$REGION 'Exception raising routines'} | |
/// <summary> Eleva una excepcion EIllegalDateTime </summary> | |
procedure IllegalDateTimeError(const Day, Month, Year, Hours, Mins, Secs, MSecs: Word); | |
/// <summary> Eleva una excepcion ECannotParseDateTime </summary> | |
procedure CannotParseDateTimeError(const Value: string); inline; | |
{$ENDREGION} | |
implementation | |
uses | |
System.RTLConsts, | |
System.SysConst, | |
System.DateUtils; | |
procedure CannotParseDateTimeError(const Value: string); | |
begin | |
raise ECannotParseDateTime.CreateResFmt(@System.SysConst.SInvalidDate, [Value]); | |
end; | |
procedure IllegalDateTimeError(const Day, Month, Year, Hours, Mins, Secs, MSecs: Word); | |
function Translate(const Value: Word): string; | |
begin | |
if Value = System.DateUtils.RecodeLeaveFieldAsIs then | |
Result := System.RTLConsts.SMissingDateTimeField | |
else | |
Result := System.SysUtils.IntToStr(Value); | |
end; | |
begin | |
raise EIllegalDateTime.CreateResFmt(@System.SysConst.SInvalidDateTime, [ | |
Translate(Year) + FormatSettings.DateSeparator + | |
Translate(Month) + FormatSettings.DateSeparator + | |
Translate(Day) + ' ' + | |
Translate(Hours) + FormatSettings.TimeSeparator + | |
Translate(Mins) + FormatSettings.TimeSeparator + | |
Translate(Secs) + FormatSettings.DecimalSeparator + | |
Translate(MSecs)]); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment