github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/test/test_date_1.0.5.js (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  // 
     3  // This file is part of the go-nebulas library.
     4  // 
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  // 
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  // 
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  // 
    18  
    19  function eq(a, b) {
    20      if (a !== b) {
    21          throw new Error("Not equal: " + a + " <--> " + b);
    22      }
    23  }
    24  
    25  Blockchain.blockParse("{\"timestamp\":20000000000,\"seed\":\"\"}");
    26  
    27  var date = new Date();
    28  var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
    29  
    30  eq(date.toDateString(), "Tue Oct 11 2603");
    31  eq(Date.UTC(2603, 9, 11, 11, 33, 20), 20000000000000);
    32  eq(date.getTimezoneOffset(), 0);
    33  eq(date.toTimeString(), "11:33:20 GMT+0000 (UTC)");
    34  eq(date.toString(), "Tue Oct 11 2603 11:33:20 GMT+0000 (UTC)");
    35  eq(date.toGMTString(), "Tue, 11 Oct 2603 11:33:20 GMT");
    36  eq(date.toUTCString(), "Tue, 11 Oct 2603 11:33:20 GMT");
    37  eq(date.toISOString(), "2603-10-11T11:33:20.000Z");
    38  eq(date.toJSON(), "2603-10-11T11:33:20.000Z");
    39  eq(date.valueOf(), 20000000000000);
    40  
    41  eq(Object.prototype.toLocaleString.call(date), "Tue Oct 11 2603 11:33:20 GMT+0000 (UTC)");
    42  eq(Object.prototype.toLocaleString.call(date, 'ko-KR', { timeZone: 'UTC' }), "Tue Oct 11 2603 11:33:20 GMT+0000 (UTC)");
    43  eq(date.toLocaleString(), "10/11/2603, 11:33:20 AM");
    44  eq(date.toLocaleString('ko-KR', { timeZone: 'UTC' }), "2603. 10. 11. 오전 11:33:20");
    45  
    46  eq(date.toLocaleDateString(), "10/11/2603");
    47  eq(date.toLocaleDateString('de-DE', options), "Dienstag, 11. Oktober 2603");
    48  
    49  eq(date.toLocaleTimeString(), "11:33:20 AM");
    50  eq(date.toLocaleTimeString('ar-EG'), "١١:٣٣:٢٠ ص");
    51  
    52  
    53  eq(date.getDate(), date.getUTCDate());
    54  eq(date.getDay(), date.getUTCDay());
    55  eq(date.getFullYear(), date.getUTCFullYear());
    56  eq(date.getHours(), date.getUTCHours());
    57  eq(date.getMilliseconds(), date.getUTCMilliseconds());
    58  eq(date.getMinutes(), date.getUTCMinutes());
    59  eq(date.getMonth(), date.getUTCMonth());
    60  eq(date.getSeconds(), date.getUTCSeconds());
    61  
    62  try {
    63      date.getYear();
    64      throw new Error("should not be here.");
    65  } catch(err) {
    66      if (err != "Error: Deprecated!") {
    67          throw err;
    68      }
    69  }
    70  try {
    71      date.setYear(1999);
    72      throw new Error("should not be here.");
    73  } catch(err) {
    74      if (err != "Error: Deprecated!") {
    75          throw err;
    76      }
    77  }
    78  
    79  date = new Date('August 19, 2017 23:15:30');
    80  var date2 = new Date('August 19, 2017 23:15:30');
    81  
    82  date.setDate(12);
    83  date2.setUTCDate(12);
    84  eq(date - date2, 0);
    85  
    86  date.setMonth(1);
    87  date2.setUTCMonth(1);
    88  eq(date - date2, 0);
    89  
    90  date.setFullYear(1999);
    91  date2.setUTCFullYear(1999);
    92  eq(date - date2, 0);
    93  
    94  date.setHours(22);
    95  date2.setUTCHours(22);
    96  eq(date - date2, 0);
    97  
    98  date.setMilliseconds(420);
    99  date2.setUTCMilliseconds(420);
   100  eq(date - date2, 0);
   101  
   102  date.setMinutes(12);
   103  date2.setUTCMinutes(12);
   104  eq(date - date2, 0);
   105  
   106  date.setSeconds(12);
   107  date2.setUTCSeconds(12);
   108  eq(date - date2, 0);
   109  
   110  
   111  
   112  var d1 = new Date('December 17, 1995 00:00:00');
   113  var d2 = new Date(d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate());
   114  eq(d1.getTime(), d2.getTime());
   115  
   116  eq(Date.parse(Date()), 20000000000000);