Titanium Mobile local notifications at a certain time - ios

I have been trying to setup local notifications with Titanium mobile for iOS, using a custom date time, but its not working with custom date time. What I am trying is
var notification = Ti.App.iOS.scheduleLocalNotification({
alertBody:"Dummy text",
alertAction:"Re-Launch!",
userInfo:{"hello":"world"},
date: new Date("2015-03-22 01:45")
});
However when I use this for date, It works.
date: new Date(new Date.getTime()+8000)//Current date time + 8 secs after.
What should I do to make this work.
date: new Date("2015-03-22 01:45")
Thanks.

The date string you are passing to the constructor is not valid.
You could use something like:
date: new Date("1/20/2015 00:00:00")
Where the format is MM/DD/YYYY HH:MM:SS

Related

Getting datetime as a string in current timezone

In the MySQL DB: '2020-04-19 22:00:00'(UTC). That's also what my endpoint returns since I set the connection option dataStrings:true.
On the client, after I fetch date:
const timezone = moment.tz.guess();
const convertedDate = moment(date)
.tz(timezone)
.format();
convertedDate then equals to "2020-04-19T22:00:00+02:00" (I'm in the UTC+2 zone).
I would like to get it in the format "2020-04-20T00:00:00" instead. How can I do that?
It looks like moment(date) believes your incoming date value is in local time, not UTC. So, your timezone conversion to local time changes nothing. You can tell moment it's UTC, like this:
const timezone = moment.tz.guess();
const convertedDate = moment.utc(date)
.tz(timezone)
.format();
You do not need moment-timezone for this. With Moment by itself you can use the utc function when parsing, and the local function to convert to the user's local time zone before formatting.
moment.utc('2020-04-19 22:00:00').local().format()
//=> "2020-04-20T00:00:00+02:00"
Also, the Moment team recommends using Moment for existing projects only. For new development, we recommend using Luxon instead:
luxon.DateTime.fromSQL('2020-04-19 22:00:00', {zone: 'utc'}).toLocal().toISO()
//=> "2020-04-20T00:00:00.000+02:00"

Convert string to Date in ios by cordova problem

I want to convert this string "2018-11-13T9:24" to Date in my js Code
var date = new Date('2018-11-13T9:24');
app.dialog.alert(date, 'Date');
but in my alert, I see:
I don't have any problem with time after 10 like '2018-11-13T11:24'

Rails/React flatpickr momentjs time conversion

I have a rails/react app (just one app) in which a user is allowed to schedule a meeting using Flatpickr .
I am passing down a datetime column called "scheduled_for" so that I can use it in my react component.
This is what my "componentDidMount()" looks like:
componentDidMount = () => {
new Flatpickr(this.refs.scheduledFor, {
minDate: new Date(),
enableTime: true,
altInput: true,
altFormat: "F j, Y h:i K",
onChange: function(dateObject) { console.log(dateObject) }
});
}
There is a "scheduled_for_future" validation method in my Meeting model to prevent the meeting from being scheduled in the past.
##app/models/meeting.rb
validate :scheduled_for_future
def scheduled_for_future
if scheduled_for.present? && scheduled_for < Time.zone.now
errors.add(:scheduled_for, "Must be in future")
end
end
I want a user to be able to pick a date & time in their local time zone and have it be saved as UTC (the Heroku default).
Everything works fine on local dev but if I try to pick a time & date in production, say for example 10 minutes from now, I get the "Must be in the future" error. (this obviously occurs because my Timezone is PT and 10 minutes from now is in the past according to the server's time)
It feels like this should be simple to fix. For the sake of UX I want the client to be able to pick the time in their own time zone and have convert to UTC before saving, but just can't figure it out.
I'm not very experienced with momentjs or flatpickr so it's likely that I'm missing something very important.
Please let me know if you need any more info/ something doesn't make sense.
thanks a million
You can use moment to format the datetime on the client side to include the timezone offset. currDate, in your case would be the datetime selected in your Flatpickr calendar.
var currDate = new Date();
console.log("Current Date: " + moment(currDate).format("YYYY-MM-DD HH:mm:ssZ"));
// Returns ...
Current Date: 2017-02-25 09:38:02-05:00
Then you can pass that to up rails, as a string, and convert it to UTC before persisting in the database
2.3.1 :003 > client_date = "2017-02-25 09:38:02-05:00"
=> "2017-02-25 09:38:02-05:00"
2.3.1 :004 > utc_date = Time.zone.parse(client_date).utc
=> 2017-02-25 14:38:02 UTC

Save task with a specific date and timezone

It's a rails project. I have a form where the user can schedule tasks. For the moment I get the timezone of the browser with :
var currentTime = new Date();
var timezone_offset = currentTime.getTimezoneOffset()
And then I use it in my controller. But the problem is :
How can I save the date to be scheduled to the right moment?
I thought the answer will be to parse the date from my form and then change the offset but it doesn't work:
> time = Time.parse("2015/11/30 12:00")
=> 2015-11-30 12:00:00 +0100
> time.change(offset: '+02:00')
=> 2015-11-30 12:00:00 +0100
Maybe the answer is to create a Time.new?
My heroku server is on UTC. Some users on CET.
You would be better off getting your form to submit the time in UTC format.
Using something like moment.js (http://momentjs.com/) you can get their local time in the browser and display the date/time in their local format, but submit the UTC counterpart to the server when submitting your form.

how to get timezone from a calendar

I am trying to get the timezone from native calendar using the following code but i am getting the timezone has Asia/Calcutta instead of just 'IST'
Calendar calendarLocal = Calendar.getInstance();
// fetches time zone
TimeZone timeZone = calendarLocal.getTimeZone();
System.out.println("Time Zone getAvailableIDs() --->"+timeZone.getAvailableIDs());
String[] x=timeZone.getAvailableIDs();
for(int i=0;i<x.length;i++){
System.out.println("Time Zone IDs-->"+x[i]);
}
System.out.println("Time Zone ID--->"+timeZone.getID());
System.out.println(" Calender Default-------->>>"+timeZone.getDefault());
System.out.println("Time Zone --->"+timeZone.getTimeZone(timeZone.getID()));
Here TimeZone is Asia/Calcutta i need it to print IST
BlackBerry Java doesn't give you the time zone short codes, at least not reliably (it only gaurantees to know about the "GMT" code). You can see my answer here for information about how to code a mapping between strings like "Asia/Calcutta" and "IST". (my method mapTimeZoneCodes() in that example)
I provide a template method for setting up the mapping, and a link to this article on Desktop Java, which seems to have a pretty complete list of the time zone codes, and how to map codes to the long Java time zone strings.
It will be boring work to copy the strings into my template, but once you have it, you'll be able to easily lookup the short code based on the long name:
String longName = timeZone.toString();
String shortCode = (String)_timeZones.get(longName);

Resources