github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/1.0.5/date.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  
    20  var NebDate = (function(ProtoDate) {
    21  
    22      function NebDate() {
    23          if (!Blockchain) {
    24              throw new Error("'Blockchain' is not defined.");
    25          }
    26          if (!Blockchain.block) {
    27              throw new Error("'Blockchain.block' is not defined.");
    28          }
    29      
    30          var date = new(Function.prototype.bind.apply(ProtoDate, [ProtoDate].concat(Array.prototype.slice.call(arguments))))();
    31          if (arguments.length == 0) {
    32              // unit of timestamp is second
    33              date.setTime(Blockchain.block.timestamp * 1000);
    34          }
    35          Object.setPrototypeOf(date, NebDate.prototype);
    36          return date;
    37      }
    38      NebDate.now = function() {
    39          return new NebDate().getTime();
    40      }
    41      NebDate.UTC = function() {
    42          return ProtoDate.UTC.apply(null, Array.prototype.slice.call(arguments));
    43      }
    44      NebDate.parse = function(dateString) {
    45          return ProtoDate.parse(dateString);
    46      }
    47  
    48      NebDate.prototype.getYear = function() {
    49          throw new Error("Deprecated!");
    50      }
    51      NebDate.prototype.setYear = function() {
    52          throw new Error("Deprecated!");
    53      }
    54  
    55      NebDate.prototype.toLocaleDateString = function() {
    56          var tmp = new ProtoDate.prototype.constructor(this.getTime());
    57          return ProtoDate.prototype.toLocaleDateString.apply(tmp, Array.prototype.slice.call(arguments));
    58      }
    59  
    60      NebDate.prototype.toLocaleTimeString = function() {
    61          var tmp = new ProtoDate.prototype.constructor(this.getTime());
    62          return ProtoDate.prototype.toLocaleTimeString.apply(tmp, Array.prototype.slice.call(arguments));
    63      }
    64  
    65      NebDate.prototype.toLocaleString = function() {
    66          var tmp = new ProtoDate.prototype.constructor(this.getTime());
    67          return ProtoDate.prototype.toLocaleString.apply(tmp, Array.prototype.slice.call(arguments));
    68      }
    69  
    70      NebDate.prototype = new Proxy(NebDate.prototype, {
    71          getPrototypeOf: function(target) {
    72              throw new Error("Unsupported method!");
    73          },
    74      });
    75  
    76      Object.setPrototypeOf(NebDate.prototype, ProtoDate.prototype);
    77      return NebDate;
    78  })(Date);
    79  
    80  module.exports = NebDate;