Fernando Galindez
Posts: 0
Joined: Thu Mar 19, 2015 5:46 pm

How show in local user timezone an hour stored in Data Base

Hi,

I dont know if you can help me and have any tutorial to transform the hour data in Database to local user timezone.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How show in local user timezone an hour stored in Data Base

I have a date math library that you might want to try that, amongst other things ...changes UTC times to local times using offset based on user location as found during login ....

Happy to share it if you'd like to email me ... You can find my email information by clicking on my profile.

The library also does a number of things like having the ability to add hours, minutes, days, months, years and quarters to a date.

Please let me know :-)

Best,

Bruce

Fernando Galindez
Posts: 0
Joined: Thu Mar 19, 2015 5:46 pm

How show in local user timezone an hour stored in Data Base

Thanks Bruce... I'll send you an email with my contact. Alzó i have problems because i am a beginer and i dont know how to use the library... If you hace any document por tutorial i wold be very grateful. Best, FG

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How show in local user timezone an hour stored in Data Base

Fernando, the library is pretty self explanatory and can be imported simply by saving to your hard disk, and then in Appery selecting new, then JavaScript , then saying 'from file' and you point to the name and location of the file I send you in an email,....

The function names are the names of the functions that can be used in your appery code. I'll provide screen shots on how to bring in and use the code,,,

Fernando Galindez
Posts: 0
Joined: Thu Mar 19, 2015 5:46 pm

How show in local user timezone an hour stored in Data Base

Hi Bruce, i cant found your email in your profile. You can write me to a href="mailto:fergalindez@gmail.com" rel="nofollow"fergalindez@gmail.com/a and thanks a lot for your help.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How show in local user timezone an hour stored in Data Base

Sending it to you now....

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How show in local user timezone an hour stored in Data Base

if anyone is interested in the date math library I sent to Fernandez - I've loaded it here. Please use at your own risk :-) or pleasure. It's been genericized to also work on the server side as well (You can use it as a server side library).

Best,

Bruce

function ftolocaltime(dutcdate) {
// purpose - return a date that is in local time - given an input in UTC date format
if (dutcdate === undefined || dutcdate === null) {
dutcdate = new Date();
}
var noffset = fgetoffset(dutcdate);
// mountain time example - -7 comes back in Az throughout the year - the local time is 7 hours less than the UTC time throughout the day. subtract the offsetting millisendonds from the utcdate.... using date math....
var nlocaldate;
var nutcdate = dutcdate.getTime();
nlocaldate = nutcdate + (fmilliseconds(0, noffset, 0));
var dlocaldate = new Date(nlocaldate);
//console.log('ftolocaltime created local date time of:' + dlocaldate.toISOString() );
return dlocaldate;
}

function ftoutctime(dlocaldate) {
// purpose - return a date that is in UTC time - given an input in local time
if (dlocaldate === undefined || dlocaldate === null) {
dlocaldate = new Date();
}
var noffset = fgetoffset(dlocaldate);
// mountain time example - -7 comes back in Az throughout the year - the local time is 7 hours less than the UTC time throughout the day. subtract the offsetting millisendonds from the utcdate.... using date math....
var nlocaldate = dlocaldate.getTime();
var nutcdate = nlocaldate - (fmilliseconds(0, noffset, 0));
var dutcdate = new Date(nutcdate);
//console.log('ftolutctime created UTC date time of:' + dutcdate.toISOString() );
return dutcdate;
}

function fdatemath(dinputdate, nminutes, nhours, ndays, ssign, nmonths, nyears) {
// purpose - take an inputdate and add days, hours or minutes - as the parameters show - return a date format date that
var npriorcurrentmonth = 0;

if (nminutes === undefined nminutes === null) {
nminutes = 1;
}
if (nhours === undefined nhours === null) {
nhours = 0;
}
if (ndays === undefined ndays === null) {
ndays = 0;
}
if (ssign === undefined ssign === null) {
ssign = "+";
}
if (nmonths === undefined nmonths === null) {
nmonths = 0;
}
if (nyears === undefined nyears === null) {
nyears = 0;
}
if (dinputdate === undefined || dinputdate === null) {
dinputdate = new Date();
}
if (ssign !== "+" && ssign !== "-") {
ssign = "+";
}

var nmilliseconds2add = fmilliseconds(nminutes, nhours, ndays);
if (ssign === "-") {
nmilliseconds2add = nmilliseconds2add * -1.0;
}
var ninputdate = dinputdate.getTime();
var noutputdate = ninputdate + nmilliseconds2add;
var dreturndate = new Date(noutputdate);
var ncurrentmonth = dreturndate.getMonth(); // of note that this is a number from 0-11
if (ssign !== '+') {
nyears = nyears * -1;
}
if (nmonths !== 0) {
// then make a new date based on the months...
if (ssign !== '+') {
nmonths = nmonths * -1;
}
if (nmonths 0) {
npriorcurrentmonth = ncurrentmonth;
ncurrentmonth += nmonths;
if (ncurrentmonth 11) {
nyears += Math.floor(nmonths / 12);
ncurrentmonth = npriorcurrentmonth + (nmonths % 12); // the remainder...
} // end if current month
} // end if months2add 0
else {
// nmonths is less than zero.....
npriorcurrentmonth = ncurrentmonth;
ncurrentmonth += nmonths;
if (ncurrentmonth < 0) {
nyears += Math.floor(nmonths / 12);
ncurrentmonth = 13 + (nmonths % 12); // the remainder...
} // current month
} // end the else
} // nmonths !== 0
if (nyears !== 0) {
dreturndate.setFullYear(dreturndate.getFullYear() + nyears);
} // endif years2add
if (nmonths !== 0) {
dreturndate.setMonth(ncurrentmonth);
} // endif months2add 0
// add days now.... }
//console.log('return date in date math function is :' + dbDate( dreturndate ));
return dreturndate;
}

function dbDate(dinput) {
var sreturn = dinput.toISOString().substring(0, 23); // need 23 characters to do a good date & TIME search.....
sreturn = sreturn.replace("T", " "); // remove the t that comes back for searching
return sreturn;
}

function fmilliseconds(nminutes, nhours, ndays) {
if (nminutes === undefined nminutes === null) {
nminutes = 1;
}
if (nhours === undefined nhours === null) {
nhours = 0;
}
if (ndays === undefined || ndays === null) {
ndays = 0;
}
var nmilliseconds = 0;
nmilliseconds += nminutes * (1000 * 60); // 1000 milliseconds in a second, times 60 seconds in a minute * number of minutes
nmilliseconds += nhours * (1000 * 60 * 60); // 1000 milliseconds in a second, times 60 seconds in a minute * 60 minutes in an hour * number of hours
nmilliseconds += ndays * (1000 * 60 * 60 * 24); // 1000 milliseconds in a second, times 60 seconds in a minute * 60 minutes in an hour * number of hours * number of days
return nmilliseconds;
}

function fdisplaydatefromDB(sdfromDB, bincludetime, bAMPM) {
// date comes from DB in this format.... return it in MM:DD:YY format...
// date from DB: 2015-02-09 HH:MM:SS.999
// 01234567890123456789012
// yyyy mm dd1 2
var shours = sdfromDB.substring(11, 13);
var nhours = parseInt(shours);
var snewhours;
var sreturndate;
var sAMPM = "AM";
if (bincludetime === null bincludetime === undefined) {
bincludetime = false;
}
if (bAMPM === null bAMPM === undefined) {
bAMPM = false;
}
if (bAMPM) {
if (nhours = 12) {
sAMPM = "PM";
}
// console.log('point 1 :' + nhours);
if (nhours = 13) {
nhours = nhours - 12;
// console.log('point 2 :' + nhours);
snewhours = nhours.toString().trim() ;
if (snewhours.length === 1) {
snewhours = "0" + snewhours;
// console.log('point 3 :' + snewhours);
}
sdfromDB = sdfromDB.substring(0, 11) + snewhours + sdfromDB.substring(13);
}
}
sreturndate = sdfromDB.substring(5, 7) + "/" + sdfromDB.substring(8, 10) + "/" + sdfromDB.substring(0, 4);
if (bincludetime) {
sreturndate += " " + sdfromDB.substring(11, 16);
if (bAMPM) {
sreturndate += sAMPM;
}
}
// console.log( sreturndate );
return sreturndate;
}

// function compliments Yurii @ Appery.io
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType '';
sliceSize = sliceSize 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {
type: contentType
});
return blob;
}

function fstripheader(sinboundcontent) {
var soutboundcontent;
soutboundcontent = sinboundcontent.replace('data:image/jpeg;base64,', "");
return soutboundcontent;
}

function fgetutcnow() {
// return an ISO strign with the UTC time to send the next occurance....
var sutcdate;
var dNow = new Date();
sutcdate = dbDate(dNow);
return sutcdate;
}

Bruce7551108
Posts: 0
Joined: Sun May 24, 2015 3:56 am

How show in local user timezone an hour stored in Data Base

Bruce,
I don't see the declaration of the function fgetoffset. But you are calling that function 2 times. Could you please send me the declaration of the function fgetoffset to my E-mail a href="mailto:geekybruce@gmail.com" rel="nofollow"geekybruce@gmail.com/a

Also, if you have improved on this library, please send the updated one with screenshots if possible.

Thanks,
Bruce.

Return to “Issues”