Coder Social home page Coder Social logo

Add short date options about cipherfox HOT 2 CLOSED

gavinhungry avatar gavinhungry commented on June 1, 2024
Add short date options

from cipherfox.

Comments (2)

gavinhungry avatar gavinhungry commented on June 1, 2024

This is the nsIX509CertValidity object generated on my machine (Linux, en-US) from GitHub's certificate:

{
  "notBefore": 1457568000000000,
  "notBeforeLocalTime": "Wed 09 Mar 2016 04:00:00 PM PST",
  "notBeforeLocalDay": "03/09/2016",
  "notBeforeGMT": "Thu 10 Mar 2016 12:00:00 AM PST",
  "notAfter": 1526558400000000,
  "notAfterLocalTime": "Thu 17 May 2018 05:00:00 AM PST",
  "notAfterLocalDay": "05/17/2018",
  "notAfterGMT": "Thu 17 May 2018 12:00:00 PM PST"
}

CipherFox uses the notBeforeLocalDay and notAfterLocalDay keys to populate the $CERTISSUED and $CERTEXP formatting variables, respectively. Not all locales will present these in such a short format. This is the nsIX509CertValidity object generated by a Windows en-US machine from the same certificate:

{
  "notBefore": 1457568000000000,
  "notBeforeLocalTime": "Wednesday, March 9, 2016 4:00:00 PM",
  "notBeforeLocalDay": "Wednesday, March 9, 2016",
  "notBeforeGMT": "Thursday, March 10, 2016 12:00:00 AM",
  "notAfter": 1526558400000000,
  "notAfterLocalTime": "Thursday, May 17, 2018 5:00:00 AM",
  "notAfterLocalDay": "Thursday, May 17, 2018",
  "notAfterGMT": "Thursday, May 17, 2018 12:00:00 PM"
}

Instead, we can parse a new date object from the notBefore and notAfter timestamps (ยตs since the epoch).

from cipherfox.

gavinhungry avatar gavinhungry commented on June 1, 2024

I think Date.prototype.toLocaleDateString may get us a consistently short, localized format:

var d = new Date(cert.validity.notBefore / 1000);

// all locales currently supported by CipherFox
[
  'de-DE', 'en-US', 'es-ES', 'fr-FR',
  'hu-HU', 'ja-JP', 'ko-KR', 'ru-RU',
  'zh-CN', 'zh-TW'
].forEach(function(locale) {
  console.log(locale, d.toLocaleDateString(locale));
});
de-DE  9.3.2016
en-US  3/9/2016
es-ES  9/3/2016
fr-FR  09/03/2016
hu-HU  2016. 03. 09.
ja-JP  2016/3/9
ko-KR  2016. 3. 9.
ru-RU  09.03.2016
zh-CN  2016/3/9
zh-TW  2016/3/9

from cipherfox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.