AppInventor: how to insert DateTime into Google Spreadsheet and show only recent DateTime - datetime

I am new to this forum so I hope I asking my question in the right place.
I have a problem inserting a datetime into a Google Spreadsheet from a form created in Appinventor2;
In app inventor2 I created a form that fills in a google spreadsheet. Basically I merged the Pizza Party example (http://appinventor.mit.edu/explore/ai2/pizzaparty.html) with this example http://puravidaapps.com/spreadsheet.php to use google spreadsheet instead of fusion table.
the user selects in how many minutes he wants his order and then sees all the orders in a table sorted by delivery time.
Problem A)
Firstly, i want to save the current datetime + the desired delay into the google spreadsheet and sort the table by this new datetime.
1) when i use the block "call clock format time" + "call clock addminutes" the spreadsheet is populated with a text, but then i can't sort the table by delivery datetime. in fact i believe the sorting is done on the number regardless of the am/pm or day of the month. so for example instead of having 4am, 6am, 2pm, 3pm i get : 2pm, 3pm, 4am, 6am.
2) I then tried to remove the block "call clock format time" and in the google form i kept the field format = text
but the google spreadsheet is populated with the following:
java.util.GregorianCalendar[time=1395531335908,areFieldsSet=true,lenient=true,zone=Europe/Dublin,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2014,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=35,SECOND=35,MILLISECOND=908,ZONE_OFFSET=0,DST_OFFSET=0]
3) I then tried to remove the block "call clock format time" and in the google form I changed the field format = time
but then the google spreadsheet isn't populated with anything.
4)I tried using the segment block, but after a while I realised the block "format time" actually returns this format: "hh:mm:ss AM/PM"
so selecting the 5 characters is not good enough because it does not take into account of the am/pm element as well as the day of the month.
5) I found a temp solution by defining the desired delivery time as a new global variable, and extracting a string in the format hh:mm by joining the blocks ".hour instant" and ".minute instant".
However this is not a final solution because what i extracted is of course a string of text and when sorting, 01:10 will be always considered smaller than 23:50 for example, regardless of the date.
So is there a way of actually saving in the google spreadsheet not a string of text, but actually the date and time?
Problem B)
Secondly, I would like to filter/show only the rows of the google spreadsheet have a delivery time expired by no more than 1 hour (as well as orders with delivery time in the future e.g. in 2 hours from now()).
I tried using some Google Visualization API Query Language commands, altering the url of the google spreadsheet (like WHERE "now() - Delivery Time < 60 mins)" (cannot remember the exact code I wrote) but unsucessfully.
Would anyone know how to filter my results?
thanks in advance
alterettore

So there's a few things to note.
If you're using Taifun's example as you mention, you'll notice that when you submit data to Google Spreadsheets using a form, the first column is always a timestamp, even if you're not submitting a date or time. Trying to send the current date/time is redundant - go ahead and make use of what Google provided.
Google Spreadsheets (and Excel) store Date/Time as a number. If you want to store a date in GS, the best way to do so is not formatted text, but by sending a number. Use AppInventor to calculate the number you need. For example, today (April 27) in GS is 41756. Noon today would be 41756.5
To generate this number, start with AI's Millisecond function. NOTE: Both GS and AI use milliseconds, but they have different 0 points, so you have to manipulate the result a bit. The formula I've used in AI in the past is this:
GS Date/Time = (Clock1.GetMillis(Clock1.Now) / 86400000) + 25569
Hope this helps!

Related

Preventing magic numbers used in firebase realtime database

So I want to specify a time after which a post gets deleted. The time is 3 months, in my code I would define this as
const THREE_MONTHS_IN_MS = 7889400000
export const TIME_AFTER_WHICH_USER_IS_DELETED = THREE_MONTHS_IN_MS
How can I define this in my database without resorting to the use of a magic number? Basically it looks like this right now:
timeAfterWhichUserIsDeleted: 7889400000
Or as a direct screenshot of the database: https://gyazo.com/67abfdc329e1e36aae4e66b0da4b4f75
I would like to avoid this value in the database and instead have it be more readable.
Any tips or suggestions?
The 7889400000 is a UNIX timestamp, indicating a number of milliseconds since the epic. While you can store a value indicating the same moment in a different format, you'll want to make sure that the format you use still allows you to query the value.
A common format that is both readable and queryable it ISO-8859-1, and my current time in that format would be 2022-03-22 06:50:48.
I noticed after re-reading your question that your timeAfterWhichUserIsDeleted is actually an interval and not a moment. If the interval is always going to be in months, you could store countOfMonthsAfterWhichUserIsDeleted: 3 as a more readable form of the same intent. Just note that 3 is equally magic as 7889400000 and the main difference is that I've named the field more meaningfully.

Kibana KQL search saved with time range

I'm creating a saved search using Kibana Discover. On screen I can select the time range manually (default is "Last 15 minutes"). If I select "Last 24 hours" and Refresh the search, it works fine. However, when I save the search, the time range information is not saved. Whenever I open Kibana Discover and open my saved search, the time range is always the default (last 15 minutes).
I tried adding different conditions (below) to my KQL query, to no avail. :^(
and #timestamp >= "now-24h"
and #timestamp >= now-24h
and timestamp >= "now-24h"
and #timestamp >= "now-1d/d"
etc.
I also tried to "Add filter" using the #timestamp field. The only operators available are: is not, is one of, is not one of, is between, is not between, exists, does not exist.
So, I tried between now-24h and now. Yet, no results match the criteria.
However, if I manually change the time range to say, Last 30 days, then my filter works!
Question
How do I include the time range, say last 24 hours, in my KQL saved search so that it overrides the time range that is manually set on screen?
(Motivation: I don't want to change the default manual time range to be larger than the range used in all saved searches. Also, I want to make the saved searches available to a support team with minimal manual configuration.)
(I'm using Kibana v7.10.0.)

How to get a valid Date as input from GUI

I have a school practical where users enter their date of birth in a TEdit on a TForm. The user will most likely enter the date according to their custom date settings, but I want to be able to convert any or at least most date formats to the one I have stored in a .mdb Access database. How do I get an accurate and valid date from the GUI as user input?
I know of the decodedate(Date, year, month, day) procedure, but what if the user enters the date differently than system settings or as is displayed in the TDBGrid connected to the .mdb database via an ADOConnection and ADOTable? Then the procedure will crash.
Be a help to the user instead of a pain:
Is "contains" meant literally, so the user can actually also enter dates with leading and/or trailing spaces? Such things occur, especially when copying texts from elsewhere. Trimming off such whitespaces is easy, so allow this. See trim()
Avoid generic error messages but instead make them as precise as possible:
Wrong length? Tell what you expect and what you got instead, i.e.: "Expected length: 10, but got 8 instead."
No delimiter at expected position? Tell so, i.e.: "Expected delimiter "/" as 5th letter, but got "3" instead."
Illegal month? Tell so, i.e: "Expected "1" or "01" thru "12" as month, but got "23" instead."
Try to collect multiple error messages at once, so the user can see all of his mistakes and fix them in one go, instead of being penalized again and again with just one message per take.
Detect patterns and make them restrictive:
Pos #1 is in ['0'.. '2'] and pos #2 thru #4 is in ['0'.. '9']? Looks like a year from which we can proceed:
Pos #5 is in ['/', '-', '.']?
Pos #6 is '0' and pos #7 is in ['1'.. '9']? Or pos #6 is '1' and pos #7 is in ['0'.. '2']?
...and so on. That way you can much better recognize which format has been chosen and you can give much more precise error messages. It will also lead to ambiguous input, such as 4/10/2016 from which you don't know if 4 is a day or a month.
Check against illegal dates: which months cannot have a 31th day? For February 29th see IsLeapYear()
Display the date according to what you recognized - this helps you and your user to make sure the recognition was correct. Ideally you have your three Integers of year, month and date and then convert them to text again, along with delimiters - the outcome should be in general the input you had to deal with.
Regular expressions are great in recognizing patterns and then accessing the found parts. However, it's a topic on its own and should only be used when known on its own. A regex for the format I used in this example would be /([0-2][0-9]{3})[/.-](0?[1-9]|1[0-2])[/.-](0?[1-9]|[12][0-9]|3[01])/ where you can easily access $1 as year, $2 as one or two digit month and $3 as one or two digit day. You "only" have to check against illegal dates.
As #AndreasReijbrand pointed out, a TDateTimePicker would be the correct method to receive a date as user input on a GUI. The TDateTimePicker does all the validation work for you. After much debate, we were eventually allowed to use it. I post this new answer with some important insights to the TDateTimePicker component:
The TDateTimePicker automatically changes to the local set date format of the pc. So validation of that is unnecessary.
Conversion of date display format (yyyy/mm/dd or yyyy-mm-dd) from the .mdb Access database to the TDateTimePicker and vice versa is unnecessary. This is also done automatically. (Starting to see why there was so much criticism for the original lack of use of this component.)
The DateTimePicker does not allow negative values or non-sensical values such as (0030/09/08 or 2003/89/89).

create date formatted custom_meta field in wordpress admin

I have created a custom meta field to be used within a custom post type, that is to be the start time of a series of events. However, I would like to run my query_posts off of this value, but it is not formatted in date/time format, therefore '1:00pm' shows up in the list before '9:00am'. Is it possible to format this value in the db or at least prior to setting the 'meta_key' meta_value in my arguments for my query?
I've come across this problem a few times before. I'm going to use my most recent example because it sounds like it's along the same lines of what you're doing.
I had to create an event calendar using WordPress. In my custom post type, I had two fields: a start time and an end time. Instead of just using "1:00pm" as the start and end times, I also included the dates. This would allow for events that would last an entire weekend like a concert or a race.
What I'm getting at here, is once the user submitted that the event started on January 3, 2012 at 8:00 am and ended on January 3, 2012 at 10:00 am, I saved both of the variables using strtotime(). If you're not familiar with this function, you can read more about it here: http://us.php.net/manual/en/function.strtotime.php.
I also suggest using the datetime picker add-on for jQuery UI http://trentrichardson.com/examples/timepicker/.
I hope this helped. I know I was a little vague at times. If you need me to explain anything in more detail, don't be afraid to ask.

Setting report to current date

I have a report where it shows meetings and their requirements. However i just want the report to show ONLY today's stuff--not the entire week's worth.
I tried setting my group header (i'm grouping by day) to currentdate but yet it still shows me the entire week. I then have to go to the grouping tree and select today's date. Is there any way to run my report and have it ONLY show today's stuff and nothing else???
Any ideas?
Use the select expert to limit the results to today's date. printdate is a special Crystal Formula keyword.
{table.date_field} = printdate
Or, if you're working with a datetime db field you can strip the time with CDate
CDate({table.date_field}) = printdate
One way would be to change your query so that it's only getting one day's worth of data; that is, assuming your data contains a date field. To take it a step further, you could add date parameters to the query itself and leave the group headers as is. That way, you can have one day of data, or data from a specific date range.
If you have no influence (or desire) to change the way data comes into Crystal Reports, you could also add a formula via the Section Expert to suppress the group or detail section unless the date is the current date.

Resources