All Downloads are FREE. Search and download functionalities are using the official Maven repository.

temper.std.temporal.TemporalGlobal.map Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
{ "version": 3, "file": "java/std/src/main/java/temper/std/temporal/TemporalGlobal.java", "sources": [ "std/temporal.temper.md" ], "sourcesContent": [ "# Temporal\n\nWe're creating an initial Date type to help with developing\nTemper's machinery to connect to existing Date types in\ntarget languages.\n\nSome facts about the Gregorian calendar.\n\n    /** Indexed by the month number: 1 = January */\n    let daysInMonth = [\n      0,\n      /* January   */ 31,\n      /* February  */ 28, // Special case leap days\n      /* March     */ 31,\n      /* April     */ 30,\n      /* May       */ 31,\n      /* June      */ 30,\n      /* July      */ 31,\n      /* August    */ 31,\n      /* September */ 30,\n      /* October   */ 31,\n      /* November  */ 30,\n      /* December  */ 31,\n    ];\n\n    let isLeapYear(year: Int): Boolean {\n       year % 4 == 0 \u0026\u0026 (year % 100 != 0 || year % 400 == 0)\n    }\n\n    /**\n     * If the decimal representation of \\|num\\| is longer than [padding],\n     * then that representation.\n     * Otherwise any sign for [num] followed by the prefix of [padding]\n     * that would bring the integer portion up to the length of [padding].\n     *\n     * ```temper\n     * pad(\u00220000\u0022, 123) == \u00220123\u0022) \u0026\u0026\n     * pad(\u0022000\u0022, 123) == \u0022123\u0022) \u0026\u0026\n     * pad(\u002200\u0022, 123) == \u0022123\u0022) \u0026\u0026\n     * pad(\u00220000\u0022, -123) == \u0022-0123\u0022) \u0026\u0026\n     * pad(\u0022000\u0022, -123) == \u0022-123\u0022) \u0026\u0026\n     * pad(\u002200\u0022, -123) == \u0022-123\u0022)\n     * ```\n     */\n    let pad(padding: String, num: Int): String {\n      let decimal = num.toString(10);\n      var decimalCodePoints = decimal.codePoints;\n      let sign: String;\n      if (decimalCodePoints.read() == 45 /* - */) {\n        sign = \u0022-\u0022;\n        decimalCodePoints = decimalCodePoints.advance(1);\n      } else {\n        sign = \u0022\u0022;\n      }\n      let paddingCp = padding.codePoints;\n      let nNeeded = paddingCp.length - decimalCodePoints.length;\n      if (nNeeded \u003c= 0) {\n        decimal\n      } else {\n        let pad = paddingCp.limit(nNeeded).toString();\n        let decimalOnly = decimalCodePoints.toString();\n        \u0022\u0024{sign}\u0024{pad}\u0024{decimalOnly}\u0022\n      }\n    }\n\nHere's just enough of a Date type to get us started.\n\n    /**\n     * A Date identifies a day in the proleptic Gregorian calendar.\n     * It is unconnected to a time of day or a timezone.\n     */\n    @connected(\u0022Date\u0022)\n    export class Date {\n      /** The year.  1900 means 1900. */\n      @connected(\u0022Date::getYear\u0022)\n      public year: Int;\n      /** The month of the year in [1, 12]. */\n      @connected(\u0022Date::getMonth\u0022)\n      public month: Int;\n      /**\n       * The day of the month in [1, 31]\n       * additionally constrained by the length of [month].\n       */\n      @connected(\u0022Date::getDay\u0022)\n      public day: Int;\n\n      @connected(\u0022Date::constructor\u0022)\n      public constructor(year: Int, month: Int, day: Int): Void | Bubble {\n        if (1 \u003c= month \u0026\u0026 month \u003c= 12 \u0026\u0026\n            1 \u003c= day \u0026\u0026 (\n              (month != 2 || day != 29)\n              ? day \u003c= daysInMonth[month]\n              : isLeapYear(year))) {\n          this.year = year;\n          this.month = month;\n          this.day = day;\n        } else {\n          bubble();\n        }\n      }\n\n      /** An ISO 8601 Date string with dashes like \u00222000-12-31\u0022. */\n      @connected(\u0022Date::toString\u0022)\n      public toString(): String {\n         \u0022\u0024{pad(\u00220000\u0022, year)\n        }-\u0024{pad(\u002200\u0022,   month)\n        }-\u0024{pad(\u002200\u0022,   day)}\u0022\n      }\n\n      /**\n       * The count of whole years between the two dates.\n       *\n       * Think of this as floor of the magnitude of a range:\n       *\n       *     ⌊ [start, end] ⌋\n       *\n       * If you think of it as subtraction, you have to reverse\n       * the order of arguments.\n       *\n       *     ⌊ end - start ⌋, NOT ⌊ start - end ⌋\n       *\n       * \u0022Whole year\u0022 is based on month/day calculations, not\n       * day-of-year.  This means that there is one full year\n       * between 2020-03-01 and 2021-03-01 even though, because\n       * February of 2020 has 29 days, 2020-03-01 is the 61st\n       * day of 2020 but 2021-03-01 is only the 60th day of\n       * that year.\n       */\n      @connected(\u0022Date::yearsBetween\u0022)\n      public static let yearsBetween(start: Date, end: Date): Int {\n        let yearDelta = end.year - start.year;\n        let monthDelta = end.month - start.month;\n        yearDelta - (\n            // If the end month/day is before the start's then we\n            // don't have a full year.\n            (monthDelta \u003c 0 || monthDelta == 0 \u0026\u0026 end.day \u003c start.day)\n            ? 1 : 0)\n      }\n\n      /** Today's date in UTC */\n      // TODO: take a zone\n      @connected(\u0022Date::today\u0022)\n      public static let today(): Date;\n    };\n\nTODO: an auto-balancing Date builder.\nParse from ISO\nOther temporal values\nDay of week\n" ], "names": [ "daysInMonth", "isLeapYear", "year", "return", "t#132", "pad", "padding", "num", "t#185", "decimal", "t#181", "decimalCodePoints", "sign", "paddingCp", "nNeeded", "decimalOnly" ], "mappings": "AASI,cAsIE,CAAA,AAtIF,GAsIE,CAAA,AAtIF,QAsIE,CAAA;AAtIF,aAsIE,CAAA,AAtIF,IAsIE,CAAA,AAtIF,IAsIE,CAAA,AAtIF,oBAsIE,CAAA;AAtIF,aAsIE,CAAA,AAtIF,IAsIE,CAAA,AAtIF,IAsIE,CAAA;AAtIF,WAsIE,CAAA,AAtIF,IAsIE,CAAA,AAtIF,IAsIE,CAAA;AAtIF,YAsIE,MAAA,AAtIF,eAsIE,EAAA;AAtIF,WAsIE,AAtIF,eAsIE,EAAA,AAtIF;AAAA,KAsIE;AAtIF,gBAcC,AAdG,KAAW,AAAX,QAAW,CAAA,AAAf,CAAAA,eAcC;AAED,UAEC,AAF0B,QAAO,AAA9B,CAAAC,cAAU,CAAU,AAAH,GAAG,AAAT,CAAAC,QAAS,CAAW,EAAA;AAAR,eAAO,AAAP,CAAAC,UAAA,CACuB;AAAV,WAAU,AAAV,CAAAC,KAAU,CAAA;AAA/C,YAAAF,QAAI,AAAJ,EAAQ,AAAD,EAAC,AAAR,GAAa,AAAD,EAAC,CAAA,AAAb;AAAkB,gBAAAA,Q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