tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

jsdate.h (2212B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * JS Date class interface.
      9 */
     10 
     11 #ifndef jsdate_h
     12 #define jsdate_h
     13 
     14 #include "jstypes.h"
     15 
     16 #include "js/Date.h"
     17 #include "js/RootingAPI.h"
     18 #include "js/TypeDecls.h"
     19 
     20 namespace js {
     21 
     22 /*
     23 * These functions provide a C interface to the date/time object
     24 */
     25 
     26 /*
     27 * Construct a new Date Object from a time value given in milliseconds UTC
     28 * since the epoch.
     29 */
     30 extern JSObject* NewDateObjectMsec(JSContext* cx, JS::ClippedTime t,
     31                                   JS::HandleObject proto = nullptr);
     32 
     33 /*
     34 * Construct a new Date Object from an exploded local time value.
     35 *
     36 * Assert that mon < 12 to help catch off-by-one user errors, which are common
     37 * due to the 0-based month numbering copied into JS from Java (java.util.Date
     38 * in 1995).
     39 */
     40 extern JS_PUBLIC_API JSObject* NewDateObject(JSContext* cx, int year, int mon,
     41                                             int mday, int hour, int min,
     42                                             int sec);
     43 
     44 /*
     45 * Returns the current time in milliseconds since the epoch.
     46 */
     47 JS::ClippedTime DateNow(JSContext* cx);
     48 
     49 bool date_valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
     50 
     51 bool date_toPrimitive(JSContext* cx, unsigned argc, JS::Value* vp);
     52 
     53 struct YearMonthDay {
     54  // Signed year in the range [-271821, 275760].
     55  int32_t year;
     56 
     57  // 0-indexed month, i.e. 0 is January, 1 is February, ..., 11 is December.
     58  int32_t month;
     59 
     60  // 1-indexed day of month.
     61  int32_t day;
     62 };
     63 
     64 /*
     65 * Split an epoch milliseconds value into year-month-day parts.
     66 */
     67 YearMonthDay ToYearMonthDay(int64_t time);
     68 
     69 struct HourMinuteSecond {
     70  // Hours from 0 to 23.
     71  int32_t hour;
     72 
     73  // Minutes from 0 to 59.
     74  int32_t minute;
     75 
     76  // Seconds from 0 to 59.
     77  int32_t second;
     78 };
     79 
     80 /*
     81 * Split an epoch milliseconds value into hour-minute-second parts.
     82 */
     83 HourMinuteSecond ToHourMinuteSecond(int64_t epochMilliseconds);
     84 
     85 } /* namespace js */
     86 
     87 #endif /* jsdate_h */