Skip to content

Magic dates (MagicDate)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Minor Yes 5 badpractice
brainoverload

Parameters

Name Type Description Default value
authorizedDates String Allowed dates, comma separated. Example: 00010101,00010101000000,000101010000 00010101,00010101000000,000101010000

Description

Magic date is any date in your code that does not immediately become apparent without being immersed in context.

Examples

Bad

If now < '20151021' Then
    HoverBoardIsReal = Undefined;
EndIf;

Good

PredictedDate = '20151021'; 
If now < PredictedDate Then
    HoverBoardIsReal = Undefined;
EndIf;

Also, a good solution is to use a special method with "telling name" that returns constant

Function DateInventionHover()
    Return '20151021';
EndFunction

If CurrentDate < DateInventionHover() Then
    HoverBoardWillBeInvented = Undefined;
EndIf;

Snippets

Diagnostic ignorance in code

// BSLLS:MagicDate-off
// BSLLS:MagicDate-on

Parameter for config

"MagicDate": {
    "authorizedDates": "00010101,00010101000000,000101010000"
}