I have an app that needs to find objects posted to a class on parse based on the time they were created. I can get the time range in string format and I can change that to any format. How can I pull down certain ranges from the server that isn't just the entire day. Example: 2:15 until 4:30. I would need all objects created on the database between that time returned. Any ideas?
If I understand your question, you want certain objects that are created between specific time instances.( for example between 2:15 and 4:30). If I am right, then you can use the Parse query and its predicate whereKey : greaterThan: (PFQuery Class references. So the only thing that you have to do is giving the date format with hours and minutes. Then Parse will return the object based on your date predicate. Hope this helps.
Regards.
Related
I need to develop an application which identifies the date inside the given text using some NLP approach. Let's assume I have a data in DB with dates column "from", "to" and if the text is below,
Get data between 1st August and 15th August
I need to identify the dates and form the query to retrieve the data. I used Natty NLP and I was able to identify the dates. But I'm stuck for more complex time expressions like:
Get data uploaded next week
Get data uploaded last week
Here for the first one I need to identify next week Monday's date and Sunday's date and form the query same for the 2nd one. But with Natty it gives me next week from today's date. What other solutions exist? Or do I need to manipulate the expression by coding? I am using Java.
Your questions is a bit confusing, but I guess you want to achieve two things:
Identify words that represent a time expression
Map these words to a formal machine-readable representation
If that is what you need check the duckling framework, it identifies time expressions, and it normalise them into a single unique formal date representation.
Note that you need to pass a reference date, for ambiguous time expressions.
You can run it as a service and call it from your code.
Can some body tell me the best way to create the Day entity in Coredata in one go for a diary app?
PS : I know how to make a notes app in which i can insert notes in DB, but if the don't insert notes in a specific day then the day is not shown when fetched.
I can't seem to understand how to put the notes in the respectetive days in core data ?
You could insert all the dates at the start by choosing a start date, an end date, and then using NSCalendar methods to go from one to the other one day at a time. Add a new entry for each date, and you're done.
That would be a really bad design though. It doesn't make sense to create new entries in your persistent store for every possible day you might cover. Better to only store data that you actually need than to waste time and space for data you'll never use.
To show every day in a week or month or whatever, show those dates, don't rely on Core Data to have every possible date. Show every day in the range that your UI covers. Fetch every diary entry for those dates. If there are diary entries on the date, show them. If there are no diary entries for a date, show the date with no entries. Showing every day in a specific range is a function of your controller code. It should choose the dates and ask Core Data what it has for those dates.
Ok, so you should subclass your entities first so they are easier to work with. And then you could add a function that returns an array of the object (entity) that is your diary. e.g
func getData(moc: NSManagedObjectContext) -> [Entity] {
let request: NSFetchRequest<Entity> = Entity.fetchRequest()
do {
let entityData = try moc.fetch(request)
return entityData
} catch {
// Handle errors
}
}
You could then add a predicate to this method that returns specific data inside the entity matching the arguments you pass your predicate. I know this doesn't cover your full question but i hope it helps!
I was just wondering, is there a means to store Time in Firebase using Swift? The reason why I ask is because I want to make an application that when I create a particular object, the object will start a timer that counts down from 24 hours of when it was created. When those 24 hours expire, the object is deleted. I also want to show a count down timer to show how much longer the object has left before it's deleted.
I tried storing the hour and minutes as Integers into my database but that doesn't seem very efficient since I have to worry about AM/PM, and possibly have to worry about what day it is. I was also thinking about storing the date as a string but that seems arduous in figuring out how to constantly change the string to an integer and decrement the time to show the countdown that way.
I've looked into the FirebaseServerValue.timestamp() but I can't seem to store that into Firebase. Are there any tips or ideas on how one would implement this? Thanks.
EDIT: Attempt to store FirebaseServerValue.timestamp() into Firebase:
self.firebaseRef.childByAutoId().setValue([
"individualId":individualId.text,
"timeCreated": FirebaseServerValue.timestamp()
])
However I get an error saying that '_' is not convertible to 'StringLiteralConvertible'. I tried to see if timestamp had any methods to turn it into a String or an Integer but couldn't find anything that I thought would be useful with the autocomplete.
You can use time interval and just store it like a number
var interval = NSDate().timeIntervalSince1970
And when you need the date just get it like this
var date = NSDate(timeIntervalSince1970: interval)
Currently I'm checking if a tweet was created after another tweet based on the timestamp, but this is proving inconsistent. What is working locally is not working all the time on my server. I suspect a timezone issue (my server is in another time zone).
But I was wondering if I can do this based on Twitter's unique ids for each tweet? Something in the form:
if (tweet2.id > tweet1.id) {
// tweet2 created after tweet 1
} else {
// tweet2 created before tweet 1
}
Is this possible? If not I'll ask another question about what could be going wrong with my date implementation.
Twitter ids are generated by twitter snowflake mechanism which
is an algorithm and a cluster of machines to produce it. In general
those id's are sequential so your comparison will basically hold. The
problem is those id's are currently > 64 bits so js will truncate
those. The trick is to use tweetXXX.id_str field which is the id
casted to a string for your comparison.
I haven't see your date implementation but probably you are no comparing UTC date values. Any way comparison made on datetime will not give you correct results even on ms scale there will be many tweets on same date time.
I am using CoreData. I'm adding date and some datas. I need a if statement. This is if statement will work like that :
"if this date is available in CoreData database, user won't add any data."
I used this:
if newuser.valueForKey(NSDate) as NSDate == NSDate()
This is absolutely wrong. I'm new and i don't create this if statement. how can i do this ?
Thanks already !
To compare the dates you should be using isEqualToDate:
if newuser.valueForKey(NSDate).isEqualToDate(NSDate())
But, dates are very accurate, so the current date would need to match the saved date, and that's never going to happen - at least a part of a second will have passed before you make the comparison.
So, what you really need to do is to find out what day, month and year the date is an compare those.
In a number of ways it would be best to store these values explicitly in Core Data instead of using a date object, though both would work. In either case you need to get the date components from the date in order to find out the day, month and year and then you need to compare them (possibly creating a date with only day, month and year and no time so you can compare it to the stored date which should also have no time set).