IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[Dates] Fatal error : Cannot redeclare class


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 9
    Points : 4
    Points
    4
    Par défaut [Dates] Fatal error : Cannot redeclare class
    Bonjours chers membres je vous explique
    Je bosse sous wamp5
    Quand je lancais ma page d'accueil j'avais des erreurs m'indiquant des erreurs au niveau des fichiers Date.php et DB.php je pense pet etre les avoirs resolu car j'ai plus de messages d'erreurs à part celui ci :

    Fatal error: Cannot redeclare class Date in C:\wamp\www\savoir\data\php\Date\Date.php on line 123

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    291
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2007
    Messages : 291
    Points : 217
    Points
    217
    Par défaut
    Bonjour,

    comme le dit le message d'erreur tu dois sans doute essayer de redefinir ta classe Date... Malheureusement sans ma boule de cristal je n'arrive pas à voir ton code Date.php et encore moins la ligne 123...
    Peut etre qu'un petit peu de code pourrait nous aider à t'aider...!

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    Ben pourtant ma classe est déjà déclarée donc si je fais une redéclaration servira-t-elle à quelque choses ?
    Merci d'avance

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    voila un peti bout de code là ou commence l'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
     
    class Date// c'est la que comence l'erreur
    {
        // {{{ Properties
     
        /**
         * the year
         * @var int
         */
        var $year;
     
        /**
         * the month
         * @var int
         */
        var $month;
     
        /**
         * the day
         * @var int
         */
        var $day;
     
        /**
         * the hour
         * @var int
         */
        var $hour;
     
        /**
         * the minute
         * @var int
         */
        var $minute;
     
        /**
         * the second
         * @var int
         */
        var $second;
     
        /**
         * the parts of a second
         * @var float
         */
        var $partsecond;
     
        /**
         * timezone for this date
         * @var object Date_TimeZone
         */
        var $tz;
     
        /**
         * define the default weekday abbreviation length
         * used by ::format()
         * @var int
         */
        var $getWeekdayAbbrnameLength = 3;
     
        // }}}
        // {{{ Constructor
     
        /**
         * Constructor
         *
         * Creates a new Date Object initialized to the current date/time in the
         * system-default timezone by default.  A date optionally
         * passed in may be in the ISO 8601, TIMESTAMP or UNIXTIME format,
         * or another Date object.  If no date is passed, the current date/time
         * is used.
         *
         * @access public
         * @see setDate()
         * @param mixed $date optional - date/time to initialize
         * @return object Date the new Date object
         */
        function Date($date = null)
        {
            $this->tz = Date_TimeZone::getDefault();
            if (is_null($date)) {
                $this->setDate(date("Y-m-d H:i:s"));
            } elseif (is_a($date, 'Date')) {
                $this->copy($date);
            } else {
                $this->setDate($date);
            }
        }

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    291
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2007
    Messages : 291
    Points : 217
    Points
    217
    Par défaut
    N'hésites pas à utiliser les balises c'est plus lisible

    Quel est la ligne 123? En ensuite... j'utilise pas trop les classes en php mais ça me semble bizarre tout ça... Moi je ne déclare jamais mes variables comme ça... ja mets juste $truc='bidule' et voila. Elle vient d'ou cette classe c'est toi qui l'a faite?

    Ben pourtany ma classeest dja declarer donc si je fais une redeclaration servira t'il à quelque choses ?
    Et justement l'erreur que tu as semble venir d'une redéclaration donc s'il te plait quelle est la ligne 123?

    Enfin ton problème ne semble pas être mysql, ç'aurait été mieux si tu avais posté dans php...

  6. #6
    Membre averti
    Homme Profil pro
    Lead Dev Web
    Inscrit en
    Avril 2005
    Messages
    282
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lead Dev Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2005
    Messages : 282
    Points : 390
    Points
    390
    Par défaut
    C'est ton fichier qui doit être inclu 2 fois....

  7. #7
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    Ben la ligne 123 est la ligne ou j'ai mis le commentaire //c'est là ou commence l'erreur Classe date plus presice
    EN fait cette classe je l'ai utilise pour prendre l'heure ou je me conecte à la base

  8. #8
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    291
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2007
    Messages : 291
    Points : 217
    Points
    217
    Par défaut
    As-tu verifié que tu n'incluais pas deux fois ton fichier Date.php comme l'a suggéré yannux?
    Sinon regardes si tu ne fais pas un autre "class Date...etc" avant?

    Tu bosses avec php5 (logiquement oui vu que tu as wamp5...mais ça m'étonnes un peu comment tu déclares ta classe)?

    Enfin peux tu nous donner tout ton fichier Date.php?

    Bon courage!

  9. #9
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 9
    Points : 4
    Points
    4
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    <?php
    /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
     
    // {{{ Header
     
     
    // }}}
     
    // {{{ Includes
     
    /**
     * Load Date_TimeZone.
     */
    require_once 'TimeZone.php';
     
    /**
     * Load Date_Calc.
     */
    require_once 'Calc.php';
     
    /**
     * Load Date_Span.
     */
    require_once 'Span.php';
     
    // }}}
    // {{{ Constants
     
    // {{{ Output formats Pass this to getDate().
     
    /**
     * "YYYY-MM-DD HH:MM:SS"
     */
    define('DATE_FORMAT_ISO', 1);
     
    /**
     * "YYYYMMSSTHHMMSS(Z|(+/-)HHMM)?"
     */
    define('DATE_FORMAT_ISO_BASIC', 2);
     
    /**
     * "YYYY-MM-SSTHH:MM:SS(Z|(+/-)HH:MM)?"
     */
    define('DATE_FORMAT_ISO_EXTENDED', 3);
     
    /**
     * "YYYY-MM-SSTHH:MM:SS(.S*)?(Z|(+/-)HH:MM)?"
     */
    define('DATE_FORMAT_ISO_EXTENDED_MICROTIME', 6);
     
    /**
     * "YYYYMMDDHHMMSS"
     */
    define('DATE_FORMAT_TIMESTAMP', 4);
     
    /**
     * long int, seconds since the unix epoch
     */
    define('DATE_FORMAT_UNIXTIME', 5);
     
    // }}}
     
    // }}}
    // {{{ Class: Date
     
     
    class Date {
        // {{{ Properties
     
        /**
         * the year
         * @var int
         */
        var $year;
     
        /**
         * the month
         * @var int
         */
        var $month;
     
        /**
         * the day
         * @var int
         */
        var $day;
     
        /**
         * the hour
         * @var int
         */
        var $hour;
     
        /**
         * the minute
         * @var int
         */
        var $minute;
     
        /**
         * the second
         * @var int
         */
        var $second;
     
        /**
         * the parts of a second
         * @var float
         */
        var $partsecond;
     
        /**
         * timezone for this date
         * @var object Date_TimeZone
         */
        var $tz;
     
        /**
         * define the default weekday abbreviation length
         * used by ::format()
         * @var int
         */
        var $getWeekdayAbbrnameLength = 3;
     
     
        function Date($date = null)
        {
            $this->tz = Date_TimeZone::getDefault();
            if (is_null($date)) {
                $this->setDate(date("Y-m-d H:i:s"));
            } elseif (is_a($date, 'Date')) {
                $this->copy($date);
            } else {
                $this->setDate($date);
            }
        }
     
     
        function setDate($date, $format = DATE_FORMAT_ISO)
        {
            if (
                preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i', $date, $regs)
                && $format != DATE_FORMAT_UNIXTIME) {
                // DATE_FORMAT_ISO, ISO_BASIC, ISO_EXTENDED, and TIMESTAMP
                // These formats are extremely close to each other.  This regex
                // is very loose and accepts almost any butchered format you could
                // throw at it.  e.g. 2003-10-07 19:45:15 and 2003-10071945:15
                // are the same thing in the eyes of this regex, even though the
                // latter is not a valid ISO 8601 date.
                $this->year       = $regs[1];
                $this->month      = $regs[2];
                $this->day        = $regs[3];
                $this->hour       = isset($regs[5])?$regs[5]:0;
                $this->minute     = isset($regs[6])?$regs[6]:0;
                $this->second     = isset($regs[7])?$regs[7]:0;
                $this->partsecond = isset($regs[8])?(float)$regs[8]:(float)0;
     
                // if an offset is defined, convert time to UTC
                // Date currently can't set a timezone only by offset,
                // so it has to store it as UTC
                if (isset($regs[9])) {
                    $this->toUTCbyOffset($regs[9]);
                }
            } elseif (is_numeric($date)) {
                // UNIXTIME
                $this->setDate(date("Y-m-d H:i:s", $date));
            } else {
                // unknown format
                $this->year       = 0;
                $this->month      = 1;
                $this->day        = 1;
                $this->hour       = 0;
                $this->minute     = 0;
                $this->second     = 0;
                $this->partsecond = (float)0;
            }
        }
     
        function getDate($format = DATE_FORMAT_ISO)
        {
            switch ($format) {
            case DATE_FORMAT_ISO:
                return $this->format("%Y-%m-%d %T");
                break;
            case DATE_FORMAT_ISO_BASIC:
                $format = "%Y%m%dT%H%M%S";
                if ($this->tz->getID() == 'UTC') {
                    $format .= "Z";
                }
                return $this->format($format);
                break;
            case DATE_FORMAT_ISO_EXTENDED:
                $format = "%Y-%m-%dT%H:%M:%S";
                if ($this->tz->getID() == 'UTC') {
                    $format .= "Z";
                }
                return $this->format($format);
                break;
            case DATE_FORMAT_ISO_EXTENDED_MICROTIME:
                $format = "%Y-%m-%dT%H:%M:%s";
                if ($this->tz->getID() == 'UTC') {
                    $format .= "Z";
                }
                return $this->format($format);
                break;
            case DATE_FORMAT_TIMESTAMP:
                return $this->format("%Y%m%d%H%M%S");
                break;
            case DATE_FORMAT_UNIXTIME:
                return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
                break;
            }
        }
     
     
        function copy($date)
        {
            $this->year = $date->year;
            $this->month = $date->month;
            $this->day = $date->day;
            $this->hour = $date->hour;
            $this->minute = $date->minute;
            $this->second = $date->second;
            $this->tz = $date->tz;
        }
     
     
     
         *
         * @access public
         * @param string format the format string for returned date/time
         * @return string date/time in given format
         */
        function format($format)
        {
            $output = "";
     
            for($strpos = 0; $strpos < strlen($format); $strpos++) {
                $char = substr($format,$strpos,1);
                if ($char == "%") {
                    $nextchar = substr($format,$strpos + 1,1);
                    switch ($nextchar) {
                    case "a":
                        $output .= Date_Calc::getWeekdayAbbrname($this->day,$this->month,$this->year, $this->getWeekdayAbbrnameLength);
                        break;
                    case "A":
                        $output .= Date_Calc::getWeekdayFullname($this->day,$this->month,$this->year);
                        break;
                    case "b":
                        $output .= Date_Calc::getMonthAbbrname($this->month);
                        break;
                    case "B":
                        $output .= Date_Calc::getMonthFullname($this->month);
                        break;
                    case "C":
                        $output .= sprintf("%02d",intval($this->year/100));
                        break;
                    case "d":
                        $output .= sprintf("%02d",$this->day);
                        break;
                    case "D":
                        $output .= sprintf("%02d/%02d/%02d",$this->month,$this->day,$this->year);
                        break;
                    case "e":
                        $output .= $this->day * 1; // get rid of leading zero
                        break;
                    case "E":
                        $output .= Date_Calc::dateToDays($this->day,$this->month,$this->year);
                        break;
                    case "H":
                        $output .= sprintf("%02d", $this->hour);
                        break;
                    case 'h':
                        $output .= sprintf("%d", $this->hour);
                        break;
                    case "I":
                        $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                        $output .= sprintf("%02d", $hour==0 ? 12 : $hour);
                        break;
                    case "i":
                        $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                        $output .= sprintf("%d", $hour==0 ? 12 : $hour);
                        break;
                    case "j":
                        $output .= Date_Calc::julianDate($this->day,$this->month,$this->year);
                        break;
                    case "m":
                        $output .= sprintf("%02d",$this->month);
                        break;
                    case "M":
                        $output .= sprintf("%02d",$this->minute);
                        break;
                    case "n":
                        $output .= "\n";
                        break;
                    case "O":
                        $offms = $this->tz->getOffset($this);
                        $direction = $offms >= 0 ? "+" : "-";
                        $offmins = abs($offms) / 1000 / 60;
                        $hours = $offmins / 60;
                        $minutes = $offmins % 60;
                        $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
                        break;
                    case "o":
                        $offms = $this->tz->getRawOffset($this);
                        $direction = $offms >= 0 ? "+" : "-";
                        $offmins = abs($offms) / 1000 / 60;
                        $hours = $offmins / 60;
                        $minutes = $offmins % 60;
                        $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
                        break;
                    case "p":
                        $output .= $this->hour >= 12 ? "pm" : "am";
                        break;
                    case "P":
                        $output .= $this->hour >= 12 ? "PM" : "AM";
                        break;
                    case "r":
                        $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                        $output .= sprintf("%02d:%02d:%02d %s", $hour==0 ?  12 : $hour, $this->minute, $this->second, $this->hour >= 12 ? "PM" : "AM");
                        break;
                    case "R":
                        $output .= sprintf("%02d:%02d", $this->hour, $this->minute);
                        break;
                    case "s":
                        $output .= str_replace(',', '.', sprintf("%09f", (float)((float)$this->second + $this->partsecond)));
                        break;
                    case "S":
                        $output .= sprintf("%02d", $this->second);
                        break;
                    case "t":
                        $output .= "\t";
                        break;
                    case "T":
                        $output .= sprintf("%02d:%02d:%02d", $this->hour, $this->minute, $this->second);
                        break;
                    case "w":
                        $output .= Date_Calc::dayOfWeek($this->day,$this->month,$this->year);
                        break;
                    case "U":
                        $output .= Date_Calc::weekOfYear($this->day,$this->month,$this->year);
                        break;
                    case "y":
                        $output .= substr($this->year,2,2);
                        break;
                    case "Y":
                        $output .= $this->year;
                        break;
                    case "Z":
                        $output .= $this->tz->inDaylightTime($this) ? $this->tz->getDSTShortName() : $this->tz->getShortName();
                        break;
                    case "%":
                        $output .= "%";
                        break;
                    default:
                        $output .= $char.$nextchar;
                    }
                    $strpos++;
                } else {
                    $output .= $char;
                }
            }
            return $output;
     
        }
     
     
        function getTime()
        {
            return $this->getDate(DATE_FORMAT_UNIXTIME);
        }
     
     
        function setTZ($tz)
        {
            if(is_a($tz, 'Date_Timezone')) {
                $this->tz = $tz;
            } else {
                $this->setTZbyID($tz);
            }
        }
     
     
        function setTZbyID($id)
        {
            if (Date_TimeZone::isValidID($id)) {
                $this->tz = new Date_TimeZone($id);
            } else {
                $this->tz = Date_TimeZone::getDefault();
            }
        }
     
     
        function inDaylightTime()
        {
            return $this->tz->inDaylightTime($this);
        }
     
     
        function toUTC()
        {
            if ($this->tz->getOffset($this) > 0) {
                $this->subtractSeconds(intval($this->tz->getOffset($this) / 1000));
            } else {
                $this->addSeconds(intval(abs($this->tz->getOffset($this)) / 1000));
            }
            $this->tz = new Date_TimeZone('UTC');
        }
     
        function convertTZ($tz)
        {
            // convert to UTC
            if ($this->tz->getOffset($this) > 0) {
                $this->subtractSeconds(intval(abs($this->tz->getOffset($this)) / 1000));
            } else {
                $this->addSeconds(intval(abs($this->tz->getOffset($this)) / 1000));
            }
            // convert UTC to new timezone
            if ($tz->getOffset($this) > 0) {
                $this->addSeconds(intval(abs($tz->getOffset($this)) / 1000));
            } else {
                $this->subtractSeconds(intval(abs($tz->getOffset($this)) / 1000));
            }
            $this->tz = $tz;
        }
     
     
        function convertTZbyID($id)
        {
           if (Date_TimeZone::isValidID($id)) {
              $tz = new Date_TimeZone($id);
           } else {
              $tz = Date_TimeZone::getDefault();
           }
           $this->convertTZ($tz);
        }
     
        // }}}
        // {{{ toUTCbyOffset()
     
        function toUTCbyOffset($offset)
        {
            if ($offset == "Z" || $offset == "+00:00" || $offset == "+0000") {
                $this->toUTC();
                return true;
            }
     
            if (preg_match('/([\+\-])(\d{2}):?(\d{2})/', $offset, $regs)) {
                // convert offset to seconds
                $hours  = (int) isset($regs[2])?$regs[2]:0;
                $mins   = (int) isset($regs[3])?$regs[3]:0;
                $offset = ($hours * 3600) + ($mins * 60);
     
                if (isset($regs[1]) && $regs[1] == "-") {
                    $offset *= -1;
                }
     
                if ($offset > 0) {
                    $this->subtractSeconds(intval($offset));
                } else {
                    $this->addSeconds(intval(abs($offset)));
                }
     
                $this->tz = new Date_TimeZone('UTC');
                return true;
            }
     
            return false;
        }
     
     
        function addSeconds($sec)
        {
            settype($sec, 'int');
     
            // Negative value given.
            if ($sec < 0) {
                $this->subtractSeconds(abs($sec));
                return;
            }
     
            $this->addSpan(new Date_Span($sec));
        }
     
     
        function addSpan($span)
        {
            if (!is_a($span, 'Date_Span')) {
                return;
            }
     
            $this->second += $span->second;
            if ($this->second >= 60) {
                $this->minute++;
                $this->second -= 60;
            }
     
            $this->minute += $span->minute;
            if ($this->minute >= 60) {
                $this->hour++;
                if ($this->hour >= 24) {
                    list($this->year, $this->month, $this->day) =
                        sscanf(Date_Calc::nextDay($this->day, $this->month, $this->year), "%04s%02s%02s");
                    $this->hour -= 24;
                }
                $this->minute -= 60;
            }
     
            $this->hour += $span->hour;
            if ($this->hour >= 24) {
                list($this->year, $this->month, $this->day) =
                    sscanf(Date_Calc::nextDay($this->day, $this->month, $this->year), "%04s%02s%02s");
                $this->hour -= 24;
            }
     
            $d = Date_Calc::dateToDays($this->day, $this->month, $this->year);
            $d += $span->day;
     
            list($this->year, $this->month, $this->day) =
                sscanf(Date_Calc::daysToDate($d), "%04s%02s%02s");
            $this->year  = intval($this->year);
            $this->month = intval($this->month);
            $this->day   = intval($this->day);
        }
     
     
        function subtractSeconds($sec)
        {
            settype($sec, 'int');
     
            // Negative value given.
            if ($sec < 0) {
                $this->addSeconds(abs($sec));
                return;
            }
     
            $this->subtractSpan(new Date_Span($sec));
        }
     
     
        function subtractSpan($span)
        {
            if (!is_a($span, 'Date_Span')) {
                return;
            }
            if ($span->isEmpty()) {
                return;
            }
     
            $this->second -= $span->second;
            if ($this->second < 0) {
                $this->minute--;
                $this->second += 60;
            }
     
            $this->minute -= $span->minute;
            if ($this->minute < 0) {
                $this->hour--;
                if ($this->hour < 0) {
                    list($this->year, $this->month, $this->day) =
                        sscanf(Date_Calc::prevDay($this->day, $this->month, $this->year), "%04s%02s%02s");
                    $this->hour += 24;
                }
                $this->minute += 60;
            }
     
            $this->hour -= $span->hour;
            if ($this->hour < 0) {
                list($this->year, $this->month, $this->day) =
                    sscanf(Date_Calc::prevDay($this->day, $this->month, $this->year), "%04s%02s%02s");
                $this->hour += 24;
            }
     
            $d = Date_Calc::dateToDays($this->day, $this->month, $this->year);
            $d -= $span->day;
     
            list($this->year, $this->month, $this->day) =
                sscanf(Date_Calc::daysToDate($d), "%04s%02s%02s");
            $this->year  = intval($this->year);
            $this->month = intval($this->month);
            $this->day   = intval($this->day);
        }
     
     
        function compare($d1, $d2)
        {
            $d1->convertTZ(new Date_TimeZone('UTC'));
            $d2->convertTZ(new Date_TimeZone('UTC'));
            $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year);
            $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year);
            if ($days1 < $days2) return -1;
            if ($days1 > $days2) return 1;
            if ($d1->hour < $d2->hour) return -1;
            if ($d1->hour > $d2->hour) return 1;
            if ($d1->minute < $d2->minute) return -1;
            if ($d1->minute > $d2->minute) return 1;
            if ($d1->second < $d2->second) return -1;
            if ($d1->second > $d2->second) return 1;
            return 0;
        }
     
     
        function before($when)
        {
            if (Date::compare($this,$when) == -1) {
                return true;
            } else {
                return false;
            }
        }
     
     
        function after($when)
        {
            if (Date::compare($this,$when) == 1) {
                return true;
            } else {
                return false;
            }
        }
     
     
        function equals($when)
        {
            if (Date::compare($this,$when) == 0) {
                return true;
            } else {
                return false;
            }
        }
     
     
        function isFuture()
        {
            $now = new Date();
            if ($this->after($now)) {
                return true;
            } else {
                return false;
            }
        }
     
        // }}}
        // {{{ isPast()
     
     
        function isPast()
        {
            $now = new Date();
            if ($this->before($now)) {
                return true;
            } else {
                return false;
            }
        }
     
        function isLeapYear()
        {
            return Date_Calc::isLeapYear($this->year);
        }
     
     
        function getJulianDate()
        {
            return Date_Calc::julianDate($this->day, $this->month, $this->year);
        }
     
     
        function getDayOfWeek()
        {
            return Date_Calc::dayOfWeek($this->day, $this->month, $this->year);
        }
     
        function getWeekOfYear()
        {
            return Date_Calc::weekOfYear($this->day, $this->month, $this->year);
        }
     
     
        function getQuarterOfYear()
        {
            return Date_Calc::quarterOfYear($this->day, $this->month, $this->year);
        }
     
     
        function getDaysInMonth()
        {
            return Date_Calc::daysInMonth($this->month, $this->year);
        }
     
     
        function getWeeksInMonth()
        {
            return Date_Calc::weeksInMonth($this->month, $this->year);
        }
     
     
        function getDayName($abbr = false, $length = 3)
        {
            if ($abbr) {
                return Date_Calc::getWeekdayAbbrname($this->day, $this->month, $this->year, $length);
            } else {
                return Date_Calc::getWeekdayFullname($this->day, $this->month, $this->year);
            }
        }
     
     
         */
        function getMonthName($abbr = false)
        {
            if ($abbr) {
                return Date_Calc::getMonthAbbrname($this->month);
            } else {
                return Date_Calc::getMonthFullname($this->month);
            }
        }
     
     
        function getNextDay()
        {
            $day = Date_Calc::nextDay($this->day, $this->month, $this->year, "%Y-%m-%d");
            $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
            $newDate = new Date();
            $newDate->setDate($date);
            return $newDate;
        }
     
     
        function getPrevDay()
        {
            $day = Date_Calc::prevDay($this->day, $this->month, $this->year, "%Y-%m-%d");
            $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
            $newDate = new Date();
            $newDate->setDate($date);
            return $newDate;
        }
     
     
        function getNextWeekday()
        {
            $day = Date_Calc::nextWeekday($this->day, $this->month, $this->year, "%Y-%m-%d");
            $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
            $newDate = new Date();
            $newDate->setDate($date);
            return $newDate;
        }
     
     
        function getPrevWeekday()
        {
            $day = Date_Calc::prevWeekday($this->day, $this->month, $this->year, "%Y-%m-%d");
            $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
            $newDate = new Date();
            $newDate->setDate($date);
            return $newDate;
        }
     
        function getYear()
        {
            return (int)$this->year;
        }
     
     
        function getMonth()
        {
            return (int)$this->month;
        }
     
     
        function getDay()
        {
            return (int)$this->day;
        }
     
     
         */
        function getHour()
        {
            return $this->hour;
        }
     
        function getMinute()
        {
            return $this->minute;
        }
     
     
        function getSecond()
        {
             return $this->second;
        }
     
     
        function setYear($y)
        {
            if ($y < 0 || $y > 9999) {
                $this->year = 0;
            } else {
                $this->year = $y;
            }
        }
     
     
        function setMonth($m)
        {
            if ($m < 1 || $m > 12) {
                $this->month = 1;
            } else {
                $this->month = $m;
            }
        }
     
     
        function setDay($d)
        {
            if ($d > 31 || $d < 1) {
                $this->day = 1;
            } else {
                $this->day = $d;
            }
        }
     
        function setHour($h)
        {
            if ($h > 23 || $h < 0) {
                $this->hour = 0;
            } else {
                $this->hour = $h;
            }
        }
     
        function setMinute($m)
        {
            if ($m > 59 || $m < 0) {
                $this->minute = 0;
            } else {
                $this->minute = $m;
            }
        }
     
     
        function setSecond($s) {
            if ($s > 59 || $s < 0) {
                $this->second = 0;
            } else {
                $this->second = $s;
            }
        }
     
        // }}}
    }
     
     
    ?>

  10. #10
    Membre actif
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    291
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2007
    Messages : 291
    Points : 217
    Points
    217
    Par défaut
    Tu n'as pas répondu à toutes mes questions...
    Si tu ne fais pas un effort de ton coté nous ne pouvons rien pour toi.
    Bonne journée

  11. #11
    Membre averti Avatar de johweb
    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    342
    Détails du profil
    Informations personnelles :
    Localisation : France, Sarthe (Pays de la Loire)

    Informations forums :
    Inscription : Décembre 2003
    Messages : 342
    Points : 367
    Points
    367
    Par défaut
    Et si tu renommes ta class par autre chose que "date" ?

Discussions similaires

  1. Fatal error : Cannot redeclare class
    Par abdidj dans le forum Langage
    Réponses: 4
    Dernier message: 27/03/2012, 14h19
  2. Fatal error: Cannot redeclare class
    Par legrandse dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 19/01/2011, 11h47
  3. [PEAR] Fatal error: Cannot redeclare class net_ldap_util
    Par osnet dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 28/06/2010, 21h24
  4. Réponses: 2
    Dernier message: 10/01/2010, 17h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo