Skip to content

Instantly share code, notes, and snippets.

View tofusoup429's full-sized avatar

bongkow tofusoup429

View GitHub Profile
React.useEffect(()=>{
let openRequest = indexedDB.open("testingIndexedDB", 1);
openRequest.onupgradeneeded = function() {
// triggers if the client had no database or the client has a higher version
// ...perform initialization...
console.log("onupgradeneeded");
let db = openRequest.result;
console.log(db)
};
const regex = /\d+-\d+-d+/;
//testing if exampleString includes the regex pattern.
const regexPattern=/\s+[0-9]+-[0-9]+-[0-9]+\s+/;
const exampleString =
"Hi~ call me this number 093-5353-6234 after" +
" 4:30 pm or email me at tofusoup429@gmail.com anytime.";
const result1 = regexPattern.test(exampleString);
console.log("output: ",result1);
//output: true
//extract more information for substring that matches exampleString.
const regexPattern=/\s+[0-9]+-[0-9]+-[0-9]+\s+/;
const exampleString =
"Hi~ call me this number 093-5353-6234 after" +
" 4:30 pm or email me at tofusoup429@gmail.com anytime.";
const result2 = regexPattern.exec(exampleString);
console.log("output: ",result2);
/*output: [
' 093-5353-6234 ',
//ver 1.0.7
export const excelDateToJSDate = (date:number):Date => {
//takes a number and return javascript Date object
return new Date(Math.round((date - 25569)*86400*1000));
}
export const jsDateToExcelDate = (date:Date):number => {
//takes javascript a Date object to an excel number
let returnDateTime = 25569.0 + ((date.getTime()-(date.getTimezoneOffset() * 60 * 1000)) / (1000 * 60 * 60 * 24));
return Math.floor(returnDateTime)
@tofusoup429
tofusoup429 / jsDateToExcelDate-test.js
Created August 22, 2020 09:27
jsDateToExcelDate-test.js
import {jsDateToExcelDate} from '@tofusoup429/excel-date-handlers'
let jsdate = new Date(2015,2,25)
let jsdatetoexceldate = jsDateToExcelDate(jsdate);
console.log(jsdatetoexceldate);
//42088
//note that the month of date instance starts from 0. In order to pass march, you should pass 2 instead of 3.
@tofusoup429
tofusoup429 / addDates-test.js
Created August 22, 2020 09:29
addDates-test.js
import {addDates} from '@tofusoup429/excel-date-handlers'
let addDate = addDates('20200131', 2, 'yyyy-mm-dd');
console.log(addDate)
//prints "2020-02-02", not "2020-01-33"
const {excelDateToStringDateFormat} = require('@tofusoup429/excel-date-handlers');
let stringdate= excelDateToStringDateFormat(42088,'yyyy-mm-dd');
console.log(stringdate);
//2015-03-25
let stringdate= excelDateToStringDateFormat(42088,'yyyy/mm/dd');
console.log(stringdate);
//2015/03/25
const {excelDateToJSDate} = require('@tofusoup429/excel-date-handlers');
let excelDateToJsDate = excelDateToJSDate(42088);
console.log(excelDateToJsDate);
//2015-03-25T00:00:00.000Z
Item, Pro, Con
webStorage, aaa, bbb
IndexedDB, aaa, bbb