Date.gettime() is not a function, undefined - ios

It is working on android and browser and WAS working on iOS (ionic view and device). I am saving a date inside my local Storage (import { Storage } from '#ionic/storage';) then compare it to a another date
Here's what I do And is working everywhere but suddenly, not ios under ionic view. Last test was maximum 2 weeks ago and was working as intended !
this.storage.get(filename).then((metadata_stored) => {
if (metadata_stored && metadata_stored.date && metadata_stored.date.getTime() === filedate.getTime())
//do something
and I get TypeError: metadata_stored.date.getTime() is not a function; metadata_stored.date.getTime is undefined.
filedate is create through something like this filedate: Date = new date("2017-10-14T15:44:48+02:00") (supposedly an ISO). Then it is saved in my local storage : this.storage.set(filename, { /* ... */ , date: filedate })
If I display metadata_stored.data, I get something like 2017-08-13T13:44:10.000Z
I don't get why it suddenly and silently stopped working. And how to correct it since metadate.date is an old value of filedate and filedate is a new Date(...) ! No code were changed in this section last 2 weeks.
Edit: I solved it by doing (new Date(metadata_stored.date)).getTime() instead. But I still have no idea why it stopped working for no reason...

In local storage, everything is stored as a string.
That means you should use (new Date(metadata_stored.date)).getTime() because metadata_stored.date is a string, not a Date.
let a = new Date();
let b = new Date();
// 2017-11-30T18:01:01457Z object
console.log(a, typeof a);
// 2017-11-30T18:01:01457Z object
console.log(b, typeof b);
localStorage.a = a;
localStorage.b = b;
a = localStorage.a;
b = localStorage.b;
// Thu Nov 30 18:01:01 GMT+0000 (GMT Standard Time) string
console.log(a, typeof a);
// Thu Nov 30 18:01:01 GMT+0000 (GMT Standard Time) string
console.log(b, typeof b);
a = new Date(localStorage.b);
b = new Date(localStorage.a);
// 2017-11-30T18:01:01457Z object
console.log(a, typeof a);
// 2017-11-30T18:01:01457Z object
console.log(b, typeof b);

Related

Input Date to Written form

I'm trying to write an inputted date from the adjacent cell.
i.e. date entered in A1, B1 = A1 but in word form (in Spanish).
I'm close to a solution but I'm sure making things more complicated than they need to be.
The date column(A) is currently being separated into 3;
day(B), month(D), year(F), using; =LEFT($A1;2), =MID($A1;4;2), =RIGHT($A1;4) accordingly.
In Columns C,E,G I'm using
=INDEX(IMPORTXML("https://www.buscapalabra.com/numeros-a-letras.html?cifra="&B1;"//li[1]//strong");1)
where B1 changes to E1, F1 depending on the column
finally in column H where the date will be written I use:
=trim(LOwer($C2&"de "&TEXT($D2;"mmmm")&" de "&$F2))&If(Value(Right($E2;1))=1;If(Value(MID($E2;4;1))<>1;"o";"");"")
For some reason the text value returned from the site has a space on the end and also does not properly word numbers ending in 1. Hence the use of TRIM() & the nested IF()
It works for now, I haven't tested it exhaustedly but I'd love to hear what people think, I'm new to Sheets but there has to be a cleaner way to do this.
Use custom functions:
You could do this with an Apps Script Custom Function.
First, open a bound script by selecting Tools > Script editor, and copy the following functions to the script (check inline comments for more information):
function DATE_IN_WORDS(date) {
const day = date.getDate(); // Day of the month in numbers
const year = date.getFullYear(); // Year in numbers
const options = { month: 'long'};
const month = new Intl.DateTimeFormat('es-ES', options).format(date); // Month in words
const dayAndYear = [day, year].map(number => { // Retrieve word for day and year
const url = "https://www.buscapalabra.com/numeros-a-letras.html?cifra=" + number
const resp = UrlFetchApp.fetch(url).getContentText();
const first = "<em>Como sustantivo:</em> El <strong>";
const cut = resp.substring(resp.indexOf(first), resp.length);
let word = cut.substring(first.length, cut.indexOf("</strong>")); // Get desired section of HTML
if (number.toString().slice(-1) == "1" && number.toString().slice(-2) != "11") {
word = word.trim() + "o"; // Replace "un" with "uno"
let arrayWord = word.split(" ");
let lastWord = arrayWord.pop();
if (lastWord === "veintiúno") { // If 21, replace "ú" with "u"
lastWord = lastWord.replace("ú", "u");
arrayWord.push(lastWord);
word = arrayWord.join(" ");
}
return word;
} else return word;
});
return dayAndYear.join("de " + month + " de "); // Join day, month and year
}
This function uses:
Intl.DateTimeFormat to retrieve the month in Spanish.
UrlFetchApp to fetch information from https://www.buscapalabra.com/numeros-a-letras.html.
Once it is defined, you can use the function DATE_IN_WORDS the same you would any sheets built-in function. This function would accept the cell with the Date as a parameter.
Example:
Reference:
Custom Functions in Google Sheets

Using a for loop inside ionic app works on linux but not on ios

I have made an app using ionic.
Inside it, I make a http get to get some value from my db.
Then, I loop through the result to compute the difference in terms of time between the created date of my value inside the db and the actual date.
This code works very well on my linux but when I run the code on my iphone on ios, everything works fine except the for loop which does not work... it's very strange. Someone faced it ?
ionViewWillEnter() {
let date = new Date();
this.http.get(this.server + `json.php?&id=${1}`).subscribe(resData => {
console.log(resData);
this.events = resData;
for (let i=0; i < 10; i++){
this.events[i]['unique_id'] = parseInt(this.events[i]['unique_id']);
if ((date.getTime() - new Date(this.events[i].created_at).getTime()) / 1000 < 60) {
this.events[i].ecart_now = 'there is ' + Math.round((date.getTime() - new Date(this.events[i].created_at).getTime()) / 1000) + 's';
}
}
})
}
A high possibility is the invalid date format. Safari and Internet Explorer browsers have issue with date format: new Date("2011-02-07");.
Console log new Date(this.events[i].created_at) and you would see invalid date.
Use below formats:
new Date(2011, 01, 07);
new Date(2011, 01, 07, 11, 05, 00);

Check what Date Format user uses

How can I check within my Rails app what datetime format the user currently uses as his default?
I have this method:
def local_date(date, am_pm = false)
unless am_pm
date&.localtime&.strftime('(%d.%m.%Y, %H:%M)')
else
date&.localtime&.strftime('(%d.%m.%Y, %I:%M %p)')
end
end
I need to set am_pm accordingly to users local machines datetime format WITHOUT relying on the :locale parameter as not everyone who speaks english uses am/pm
This is achievable in Rails only with the help of a bit of client side JavaScript code. The client side code would detect whether the user is using 24 hours time format or 12 hours time format, and then store that information of a cookie.
Your server side code should then read that information from the cookie and set your time format accordingly.
Add this to your app/assets/javascript/application.js file.
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));
var dateString = date.toLocaleTimeString();
//apparently toLocaleTimeString() has a bug in Chrome. toString() however returns 12/24 hour formats. If one of two contains AM/PM execute 12 hour coding.
if (dateString.match(/am|pm/i) || date.toString().match(/am|pm/i) )
{
//12 hour clock
//check if we are already rendering in 12 hours format
if(getCookie("time_format") != "twelve")
{
document.cookie = "time_format=twelve";
/***
Now force the browser to reload current page from server.
Since we had set the the cookie, the server will now render
all pages in 12 hours format
****/
location.reload(true).
}
}
else
{
//24 hour clock
document.cookie = "time_format=twenty_four";
}
In your ApplicationController
class SomeController < ApplicationController
around_faction :set_time_format
def set_time_format
if cookie[:time_format]=="twelve"
#Set your desired time format string with 12 hour style
else
#default
#Set your desired time format string with 24 hour style
end
end
end

RunState: LUA_ERROR: [string "devils_catacomb"]:1: attempt to call field `get_devil_base' (a nil value)

Hi my english is bad I have a problem
ERROR
SYSERR: Apr 11 14:16:12 :: RunState: LUA_ERROR: [string "devils_catacomb"]:1: attempt to call field `get_devil_base' (a nil value)
SYSERR: Apr 11 14:16:12 :: WriteRunningStateToSyserr: LUA_ERROR: quest >devils_catacomb.start click
SYSERR: Apr 11 14:12:32 :: RunState: LUA_ERROR: >locale/turkey/quest/object/state/deviltower_zone:1: attempt to indexglobal`positions' (a nil value)
SYSERR: Apr 11 14:12:32 :: WriteRunningStateToSyserr: LUA_ERROR: quest >deviltower_zone.start click
my deviltower_zone.lua
////////Error formed location/////////
function get_4floor_stone_pos()
local positions,j,t = {{368, 629}, {419, 630}, {428, 653}, {422, 679},
{395, 689}, {369, 679}, {361, 658},},number(i,7), positions[i];
for i = 1, 6 do
if (i != j) then
local t = positions[i];
positions[i] = positions[j];
positions[j] = t;
end
end
return positions
end
when 8016.kill with pc.get_map_index() >= 660000 and pc.get_map_index() <
670000 begin
d.setf("level", 4)
local positions,vid = deviltower_zone.get_4floor_stone_pos()
,d.spawn_mob(8017, positions[7][1], positions[7][2])
for i = 1, 6 do d.set_unique("fake" .. i , d.spawn_mob(8017,
positions[i][1], positions[i][2])) end
d.set_unique("real", vid)
server_loop_timer('devil_stone4_update', 10, pc.get_map_index())
server_timer('devil_stone4_fail1', 5*60, pc.get_map_index())
notice_multiline(gameforge.deviltower_zone._50_dNotice,d.notice)
end
There are a couple of places where you use the positions table in the right hand side of an attribution to local positions. Lua always evaluates the right hand side fully before the left hand side, so in this context, positions refers to a global variable.
First occurrence: in the line:
local positions,j,t = {{368, 629}, {419, 630}, {428, 653}, {422, 679}, {395, 689}, {369, 679}, {361, 658},},number(i,7), positions[i];
you probably meant:
local positions = {{368, 629}, {419, 630}, {428, 653}, {422, 679}, {395, 689}, {369, 679}, {361, 658},}
local j, t = number(i,7), positions[i]
(although this won't work 100% because i does not exist yet -- it's probably better to just not use the t variable.)
And in this line:
local positions,vid = deviltower_zone.get_4floor_stone_pos(), d.spawn_mob(8017, positions[7][1], positions[7][2])
You probably meant to do something like:
local positions = deviltower_zone.get_4floor_stone_pos()
local vid = d.spawn_mob(8017, positions[7][1], positions[7][2])

Set custom publish date, but publish now if it's empty

I am trying to make a custom publish date, because the user wants to use that as the publishing date and for sorting. The date will also be displayed on the page.
Here is what I want:
The user can input a date
The date can be empty (meaning it will be published now)
It has to use that date for sorting
The date has to be set to UTC time, so it's equal for everyone in the world
I am desperate and I cannot figure out how to do this.
Here is what I have tried so far: I found a neat little plugin, which displays the user's current UTC time next to the input field, so the person knows their UTC time. I modified that to always enter the current date in the input field:
var timer = setInterval(function () {
var date = $(".custom-date").val();
if (date === "") {
$(".custom-date").focus();
$(".custom-date").click();
$(".custom-date").trigger("click");
//the date has now been set on the input field
} else if (date !== "") {
var newDate = new Date(date);
var stringDate = newDate.getFullYear() + "-" + ('0' + (newDate.getMonth() + 1)).slice(-2) + "-" + ('0' + (newDate.getDate() - 1)).slice(-2) + " " + ('0' + (newDate.getHours() - offset)).slice(-2) + ":" + ('0' + newDate.getMinutes()).slice(-2) + ":" + ('0' + newDate.getSeconds()).slice(-2);
$(".custom-date").val(stringDate);
angular.element(".custom-date").scope().$apply(function () {
angular.element(".custom-date").scope().datetimePickerValue = stringDate;
});
clearInterval(timer);
}
}, 1000);
Yes, this looks like a lot... and no, it does not work. I do the focus/click/trigger on the element, because that will automatically set the time to be the user's local time. I then turn that into UTC time (offset is the UTC time offset). Then I apply the date to the element's scope and the value gets updated both in $scope and in the view (I can actually see it).
However, when I hit save and publish, the date gets reset (it's empty in the database). It's only when I physically click on the input field and select a new date it will actually update it. I like this method, as I am in 100% control of it, so is it possible? It would seem like setting the new date on the scope doesn't trigger the actual "new date has been selected".
Alternatively I have my Razor code here:
//selection is all my elements/nodes
selection.OrderByDescending(x => x.GetProperty("publishDate") != null).ThenByDescending(x => x.GetPropertyValue("publishDate")).Where(x => x.GetPropertyValue<DateTime>("publishDate") < DateTime.UtcNow);
So apparently before the Angular event is triggered, I need to, at least, call these:
$(".custom-date").trigger("click");
$(".custom-date").change();
So I did that right after I set my new date and now it works.

Resources