CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

I Do Not Think DRY Means What You Think It Means

| Comments

Perhaps this developer decided it would be better to create convenience methods than to litter their codebase with date format strings. Nothing wrong with trying to DRY up your code, but creating 13 inscrutably named date formatting functions ain’t the way to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

function formatDate1($date)
{
    return date('n-j-y', $date);
}

function formatDate2($date)
{
    return date('n/j/Y', $date);
}

function formatDate2a($date)
{
    return date('n/j/Y g:ia', $date);
}

function formatDate2b($date)
{
    return date('n.j.Y g:ia', $date);
}

function formatDate3($date)
{
    return date('n/j/y', $date);
}

function formatDate11($date)
{
    return date('n/j', $date);
}

function formatDate4($date)
{
    return date('F j, Y', $date);
}

function formatDate5($date)
{
    return date('F j, Y  g:i:s A', $date);
}

function formatDate6($date)
{
    return date('j-M', $date);
}

function formatDate8($date)
{
    return date('F j, Y  g:i A', $date);
}

function formatDate9($date)
{
    return date('n.j.Y', $date);
}

function formatDate10($date)
{
    return date('M Y', $date);
}

function formatDate12($date)
{
    return date('m/d/Y', $date);
}

I was able to confirm, thanks to further research by today’s anonymous submitter, that at least half of these functions are currently in use.

[EDIT: The wikipedia link wasn’t encoded properly when I posted this. Fixed! Thanks to @papayasoft for pointing it out.]

Comments