I'm making use of the datepicker from Element Ui where the user can select a range in dates. When the user fills in the datepicker, this is what I get back: ['2018-01', '2019-02'] . So just an array with two String elements. NOT a Date() object.
When dynamically outputting this to the user, I would like to show it as: January 2018 - February 2019
I got it somewhat working in my project but the code just really sucks and also doesn't work properly either. Checkout this gif of my current project and somewhat desired result. I was wondering if someone knows a good and easy way of achieving my desired result without too much hassle. I cannot use methods like toLocaleDateString() because it isn't a Date() object. I've got my code working in a Codesandbox. If any if you guys knows a solution feel free to edit the listed Codesandbox, I would highly highly appreciate it!
In the Codesandbox I got a computed property formateDate. The basic idea of the computed property is to cut the elements of the array I get back from the datepicker before and after the - effectively giving me the first & second month and first & second year. That data I store in these variables:
let monthOne;
let monthTwo;
let yearOne;
let yearTwo;
Since I get the months back as '01' and '02' for example, I created an array of objects to transform the '01' and '02' to January and February with a for loop. I then store the result in a new variable with:
displayDate = monthOne + ' ' + yearOne + ' - ' + monthTwo + ' ' + yearTwo;
Lastly, I tried to store that result into the timeperiodDisplayString at the correct index in the experience array of objects. Anyway, I'm probably overcomplicating this way to hard so I would REALLY appreciate any help with this.
Maybe you could map over the result from the datepicker component to create an array of Date objects. So you can use toLocaleDateString()
Something like this should work:
['2018-01', '2019-02'].map((date) => {
const split = date.split('-');
return new Date(split[0], +split[1] - 1);
});
You can use parse() function from javascript.
var d = Date.parse("2019-01");
console.log(new Date(d));
Related
I keep getting errors while trying to create blog posts via API calls to BigCommerce, due to the published_date_iso8601 field.
This field expects the date string in this kind of format "5/18/2018 1:26:42 PM", as per the docs here: https://developer.bigcommerce.com/api-reference/1b41aac9b9f54-create-a-blog-post
My data has the dates in this format: "2022-05-12T13:09:23-07:00"
I am using Javascript, and I have tried multiple ways to transform the format, but no success so far.
I have tried built-in JS Date methods
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = new Date(originalDate).toISOString()
I have tried using Moment
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = moment(
originalDate
).format('DD/MM/YYYY HH:mm:ss A')
And multiple variations of formatting besides those 2 examples, but I still can't get the post to go through. The error is only a 400 code with no message.
Anyone know how to format this?
Try using the published_date field and new Date('2022-05-12T13:09:23-07:00').toUTCString()?
Hopefully, this should work for you.
A
I'm struggling with some of the formatting for parameters inside the recurrenceRule when trying to create a new event with Expo Calendar. I can't seem to find any robust recurrence examples in the docs or anywhere else for that matter. One specific thing I'm struggling is daysOfTheWeek, where I'm trying to pass multiple days but I'm not even sure if you can.
Does anyone have a good working example of the recurrenceRule in action?
After struggling with this myself I found that if you look up types in your Calendar.d.ts file it should give you the required structure of the recurrenceRule.
export declare type RecurrenceRule = {
frequency: string
interval?: number // #default 1
endDate?: string | Date
occurrence?: number
daysOfTheWeek?: DaysOfTheWeek[]
daysOfTheMonth?: number[]
monthsOfTheYear?: MonthOfTheYear[]
weeksOfTheYear?: number[]
daysOfTheYear?: number[]
setPositions?: number[]
};
So if your use case is like mine and you just want the event to occur only once something like this will work: recurrenceRule: {frequency: 'DAILY', occurrence: 1} I think. Expo-documentation says recurrence rule can be set to null, but this throws an error. Hope this helps!
I am trying to create a calendar view in which there are events displayed with start and end times on one label. Something like:
2:30pm - 4:30pm
My model has a SimpleObjectProperty<LocalTime> for each of these times. I know that I could concatenate these by doing something like:
label(Bindings.concat(model.startTime, " - ", model.endTime))
But I would still need formatting for each time. Knowing how to do this would certainly help me in the future with other equally complex binding transformations. Or would it just be easier to attach listeners to each time property that would update the label text?
I think I found my own answer, but anyone can feel free to let me know if this is good practice or not.
root {
...
val timeFormat = DateTimeFormatter.ofPattern("h:mma")
label(stringBinding(model.startTime, model.endTime) {
val startTime = model.startTime.value
val endTime = model.endTime.value
"${startTime.format(timeFormat)} - ${endTime.format(timeFormat)}"
})
...
}
I am working on script where users can make certain type of orders. Now when users make an order they can choose how long they wont it to last in # of days. Once the order is placed I need to approve their order and that approval date is recorded inside my database. Now what I need is to show inside their user panel how much days their package will last since the day of my approval. So for example if I approved their order September 08, 2013 and they choosed for the order to last 7 days, I wont them to see inside they panel for every next day they login how much days they have left, so 7days, 6days, 5days, etc... all the way to "0 Days" when they come to their panel on September 16, 2013.
I have following variables for those two values:
$row_ordersResults['date'] - the date I approved the order
$row_ordersResults['drip_feed'] - # of days they wont for their order to last
I did tried to lots of combinations by myself but I am totally stuck with this and cant make it work.
Thanks for help!
The libraries at momentjs.com is pretty cool. But if you just wanted something simple to calculate the "date difference" between two time values, there is a relatively simple way to do it. I assume you wanted it done in Javascript.
All you need to do is to clear out the hour/minute/second/millisecond fields of the two dates, calculate their differences in days. Put the script below in any web browser and you'll see how it works.
<script>
function foo() {
var d1 = new Date(2013, 8, 12, 13, 40, 1, 333); // any date value, last 4 params can be anything
var d2 = new Date(2013, 9, 3, 11, 42, 32, 533);
d1.setHours(0); d1.setMinutes(0); d1.setSeconds(0); d1.setMilliseconds(0);
d2.setHours(0); d2.setMinutes(0); d2.setSeconds(0); d2.setMilliseconds(0);
daysLeft = (d2.getTime() - d1.getTime())/(24*60*60*1000);
alert('Dear customer, there is(are) ' + daysLeft + ' day(s) left on your order!' );
}
</script>
Show Remaining Days on Order
EDIT: adding PHP version
<?php
$d1 = New DateTime('2013-08-28 06:25:00');
$d2 = new DateTime(); // now
$drip = 55;
$interval = $d2->diff($d1); // time difference
$days_left = $drip - $interval->format('%a'); // in days, subtract from drip
echo "There are $days_left days left\n";
?>
I hope I don't get marked down for not suggesting a specific answer, but time and date calculations are very tedious and JavaScript's Date() provides limited options. So rather than offer some ugly code, I suggest you take a look at moment.js at momentjs.com. Once you attach the script to your pages, you can easily manage all kind of date formats, and set up a function that will allow you to do math on dates and automatically generate your date ranges - it will even let you format them in to user friendly formats like "in 3 days", which I think is what you want. If your app has anything to do with time, and most do, I can't recommend Moment highly enough.
I asked on SO a few days ago what was the simplest quickest way to build a wrapper around a recently completed database. I took the advice and used sqlmetal to build linq classes around my database design.
Now I am having two problems. One, I don't know LINQ. And, two, I have been shocked to realize how hard it is to learn. I have a book on LINQ (Linq In Action by Manning) and it has helped some but at the end of the day it is going to take me a couple of weeks to get traction and I need to make some progress on my project today.
So, I am looking for some help getting started.
Click HERE To see my simple database schema.
Click HERE to see the vb class that was generated for the schema.
My needs are simple. I have a console app. The main table is the SupplyModel table. Most of the other tables are child tables of the SupplyModel table.
I want to iterate through each of Supply Model records. I want to grab the data for a supply model and then DoStuff with the data. And I also need to iterate through the child records, for each supply model, for example the NumberedInventories and DoStuff with that as well.
I need help doing this in VB rather than C# if possible. I am not looking for the whole solution...if you can supply a couple of code-snippets to get me on my way that would be great.
Thanks for your help.
EDIT
For the record I have already written the following code...
Dim _dataContext As DataContext = New DataContext(ConnectionStrings("SupplyModelDB").ConnectionString)
Dim SMs As Table(Of Data.SupplyModels) = _dataContext.GetTable(Of Data.SupplyModels)()
Dim query = From sm In SMs Where sm.SupplyModelID = 1 Select sm
This code is working...I have a query object and I can use ObjectDumper to enumerate and dump the data...but I still can't figure it out...because ObjectDumper uses reflection and other language constructs I don't get. It DOES enumerate both the parent and child data just like I want (when level=2).
PLEASE HELP...I'M stuck. Help!
Seth
in C# it would be:
var result = from s in _dataContent.SupplyModels where s.SupplyModelID==1 select s;
foreach(SupplyModel item in result)
{
// do stuff
foreach(SupplyModelChild child in item.SupplyModelChilds)
{
//do more stuff on the child
}
}
and a VB.NET version (from the Telerik code converter)
Dim result As var = From s In _dataContent.SupplyModels _
Where s.SupplyModelID = 1 _
Select s
For Each item As SupplyModel In result
' do stuff
'do more stuff on the child
For Each child As SupplyModelChild In item.SupplyModelChilds
Next
Next