読める時刻 ⇔ 雪ふりかけ雑変換

    @@ -6,7 +6,7 @@ * @javascript_url */ -void (s => prompt('', /\D/.test(s) ? String(BigInt(new Date(s.replace(/[年月]/g, '/').replace(/時分/g, ':').replace(/[^\/:\d\s]/g, '')).getTime()) << 16n) : new Date(Number(BigInt(s) >> 16n)).toLocaleString()))( +void (s => prompt('', /\D/.test(s) ? String(BigInt(new Date(s.replace(/[年月]/g, '/').replace(/時分/g, ':').replace(/[^\/:\d\s]/g, '')).getTime()) << BigInt(16)) : new Date(Number(BigInt(s) >> BigInt(16))).toLocaleString()))( prompt('time or snowflake', '') ); @@ -17,3 +17,7 @@ ので最大 65536000 ほど素の値にプラスされている可能性がある さらに秒数なしの時刻を入れた場合、最大 3932160000(60000n << 16n)ほどの開きがある */ + +/* +16n って書いたら Hatena::Let が混乱して Packed 全部消えたので、長いけど BigInt(16) にしとく +*/
  • /*
     * @title 読める時刻 ⇔ 雪ふりかけ雑変換
     * @description 忘れるのでメモ。
     * @include http://*
     * @license MIT License
     * @javascript_url 
     */
    
    void (s => prompt('', /\D/.test(s) ? String(BigInt(new Date(s.replace(/[年月]/g, '/').replace(/時分/g, ':').replace(/[^\/:\d\s]/g, '')).getTime()) << BigInt(16)) : new Date(Number(BigInt(s) >> BigInt(16))).toLocaleString()))(
     prompt('time or snowflake', '')
    );
    
    /*
    https://github.com/tootsuite/mastodon/blob/a24605961a1572f7e1800cc177b5b7defe45969c/lib/mastodon/snowflake.rb#L141-L146
    ミリ秒をランダムで付加した後、さらに 16進数で下 4桁分(2進数で 16桁分)空けて
    0x0000~0xffff のランダムな値を埋め込んでいる
    ので最大 65536000 ほど素の値にプラスされている可能性がある
    さらに秒数なしの時刻を入れた場合、最大 3932160000(60000n << 16n)ほどの開きがある
    */
    
    /*
    16n って書いたら Hatena::Let が混乱して Packed 全部消えたので、長いけど BigInt(16) にしとく
    */
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2020/07/19 10:11:03 - 2020-07-19
  2. 2020/07/18 11:19:23 - 2020-07-18
  3. 2020/07/18 10:48:04 - 2020-07-18