#Dates in JavaScript
Explore tagged Tumblr posts
tpointtech12 · 10 months ago
Text
Everything You Need to Know About JavaScript Date Add Day
Tumblr media
When Working With Dates in JavaScript, adding days to a date is a common yet essential task. JavaScript provides a straightforward way to achieve this by manipulating the Date object using methods like setDate and getDate.
By creating a function to add days, you can easily calculate future or past dates. For more complex date operations or handling various edge cases, consider using date libraries like Moment.js or date-fns.
For a comprehensive guide and additional resources on JavaScript date manipulation, including adding days, TpointTech offers valuable tutorials and examples to help you master this crucial aspect of programming.
Understanding JavaScript Date Objects
In JavaScript, the Date object is used to work with dates and times. You can create a Date object using the Date constructor, which can take different formats such as a string, a number representing milliseconds since January 1, 1970, or individual date and time components.
let today = new Date();
console.log(today); // Outputs the current date and time
To add days to a date, you'll need to manipulate this Date object.
Adding Days to a Date
JavaScript doesn’t have a built-in method to directly add days to a date, but you can achieve this by using the following approach:
Get the Current Date: Start by obtaining the current date using the Date object.
Add Days: To add days, you can manipulate the date by modifying the day of the month.
Here’s a step-by-step method to add days to a Date object:
function addDays(date, days) {
    let result = new Date(date); // Create a copy of the date
    result.setDate(result.getDate() + days); // Add the specified number of days
    return result;
}
let today = new Date();
let futureDate = addDays(today, 5);
console.log(futureDate); // Outputs the date 5 days from today
In this code, the addDays function takes two parameters: the original date and the number of days to add. It creates a new Date object based on the original date and modifies it by adding the specified number of days using the setDate method. The getDate method retrieves the current day of the month, and by adding days to it, the date is updated.
Handling Edge Cases
When adding days, be mindful of edge cases, such as month and year boundaries. The Date object automatically handles transitions between months and years. For example, adding days to a date at the end of one month will correctly roll over to the next month.
let date = new Date('2024-08-30');
let newDate = addDays(date, 5);
console.log(newDate); // Outputs 2024-09-04
In this example, adding 5 days to August 30 results in September 4, demonstrating how JavaScript correctly manages month transitions.
Working with Time Zones
JavaScript dates are sensitive to time zones. The Date object represents dates in the local time zone of the system where the script is running. To avoid issues with time zones, especially when working with applications across different regions, you may need to convert between time zones or use libraries designed for handling time zones.
Using Libraries for Advanced Date Operations
For more complex date manipulations, including adding days, consider using a date library like Moment.js or date-fns. These libraries provide additional functionality and simplify date arithmetic:
Using Moment.js:
let moment = require('moment');
let today = moment();
let futureDate = today.add(5, 'days');
console.log(futureDate.format('YYYY-MM-DD'));
Using date-fns:
let { addDays } = require('date-fns');
let today = new Date();
let futureDate = addDays(today, 5);
console.log(futureDate.toISOString().split('T')[0]);
These libraries offer a more intuitive API for date manipulation and can be particularly useful in large projects.
Conclusion
Mastering the art of Adding Days to a Date in JavaScript is essential for effective data management in your applications. By using the Date object and its methods, you can easily manipulate dates to meet your needs, whether you're scheduling events or calculating deadlines.
For more complex date operations, leveraging libraries like Moment.js or date-fns can provide added convenience and functionality.
To further enhance your JavaScript skills and explore advanced date handling techniques, TpointTech offers comprehensive tutorials and resources. Embracing these tools and practices will ensure your date manipulations are accurate and efficient.
0 notes
ao3feed-bakusquad · 5 months ago
Note
Why are the same fics getting posted multiple times? I’m getting notifications for the same fics over and over throughout the day?
This trouble is caused when either AO3 starts producing multiple entries for the exact same story, or extreme lag causes errors that make IFTTT either load the wrong feed entries or consider previous entries to be new, when in reality they are not.
I have compensated for this issue by adding a date check to the code, that tests what day of the month the story was posted and compares it to the present date. When the issue grew worse, I added time checks too (that way posts from the previous day only post in the early morning, posts from the early morning won't post after noon, etc.).
Unfortunately when the repeat entries show up shortly after a work is posted, rather that at a later date or time, the date and time checks don't really help. My system is also not as helpful at the end of the month, since some months have 31 days, instead of 30.
If IFTTT actually left the date in Coordinated Universal Time like it is in the actual feed, instead of changing it to a weirdly formatted string before submitting it to my javascript filter code, the time and date tests would be far easier to program. 😠
I'll try to work on the code some more and see if I can find some compact javascript that will make the time and date checks work better. (The filtering, autotagging and such has me near the character limit for custom code).
3 notes · View notes
flock-of-cassowaries · 3 months ago
Text
Okay, but having spent a few hours Friday morning fiddling with holiday date-calculation algorithms in JavaScript (I program corporate phone systems), I’m pretty sure that anyone who can tell you when Easter 2030 is without having googled “table of Easter dates by year” is either a wizard, or absolutely full of shit.
Because seriously, what the fuck.
Tumblr media
55K notes · View notes
s4ppy-link · 4 months ago
Text
Tumblr media
0 notes
nicolae · 10 months ago
Text
Tipuri de date primitive în JavaScript - Șiruri
Tipurile primitive folosesc un format fix; unele pot conţine doar un număr limitat de anumite valori. În schimb, obiectele sunt mai complexe, în special cuprinzând metode și proprietăți. Cu excepția lui null și undefined, tipurile primitive au un înveliș de obiect corespunzător cu metode specifice tipului de date. Prin urmare, veți găsi pe această pagină descrieri ale unor metode. Şiruri Șirul în…
0 notes
xumoonhao · 11 months ago
Text
Tumblr media
so far, hehe <3
1 note · View note
divinector · 1 year ago
Text
Tumblr media
Date Differences Widget
0 notes
roseband · 2 years ago
Text
we fully got my automation system working at my job now (which... literally follows the same way i automate my gifs lmfao... mixed with an additional step that uses excel)
sooooooo since it's yearly review season I'd better get a huge raise and bonus tbh
0 notes
side-teched · 2 years ago
Text
Javascript date jank
So I'd thought I'd share a lovely piece of Javascript jank one of the other devs at work encountered.
Also, before we begin: this isn't implementation advice, don't do this. It is bad. It's just some fun stuff we found. (with that out of the way...)
So what they were trying to do was get a date object for a specific amount of time before/after another date object. This is what they tried:
let myDate = new Date() let myNewDate = new Date(myDate - (numMinutes * 60 * 1000))
Hopefully it's pretty clear what it's trying to do. It's trying to make a Date numMinutes before myDate. And this does what you would expect: so far so good!
So next they were trying to get a Date object for numMinutes later than myDate. Given what we just saw, easy right?
let myDate = new Date() let myNewDate = new Date(myDate + (numMinutes * 60 * 1000))
And just quickly typing this into the console as sanity check (on Firefox):
Invalid Date
huh? Wha?
Yeah, it took me a sec too.
Basically, what's going on here is the Javascript interpreter is trying be helpful. When the interpreter is running the version with the minus, it sees you are trying to subtract a number from a Date object. This doesn't make any sense, so it ever helpfully steps in and just tries to make it work. And it does. It decides it needs to coerce the type of at least one of the variables. It figures out if it converts the date into a Unix timestamp (which is just a number) the subtraction works! The resulting number is given to the Date constructor and it interprets the number as a Unix timestamp and spits out the correct answer.
Yipeeeeeee
But why does the version with the plus not work?
It's the same principle. The interpreter sees that you are trying to add a Date and a number, which doesn't make any sense. So it tries to be helpful and make the types work. It just so happens the interpreter figures out if it casts the Date to a string and the number to a string they can be plussed together. This makes it a string concatenation. So a valid date string with a random number on the end get passed to the Date constructor, and hey presto, Invalid Date!
0 notes
manonamora-if · 10 months ago
Text
Tumblr media
The 100% Good Twine SugarCube Guide!
The 100% Good Twine SugarCube Guide is a coding guide for the SugarCube format of Twine. It is meant as an alternative to the SugarCube documentation, with further explanations, interactive examples, and organised by difficulty. The goal of this guide is to make the learning curve for new SugarCube user less steep, and provide a comprehensive and wide look over the format.
VIEW / DOWNLOAD THE GUIDE!!!!
The Guide is compartmentalised in (currently) four categories:
THE BASICS or the absolute basics to start with SugarCube. No need for extra knowledge. Just the base needed to make something.
THE BASICS + adding interactivity, and creating a fully rounded IF game May require a bit of CSS knowledge (formatting rules)
INTERMEDIATE MODE adding more customisation and complex code Will probably require some CSS knowledge, and maybe some JavaScript
ADVANCE USE the most complex macros and APIs Will surely require some JavaScript/jQuery knowledge
Note: The Advanced Use includes all the APIs, macros, and methods not covered by the previous categories. This includes code requiring very advance knowledge of JavaScript/jQuery to be used properly.
Each category explains many aspects of the format, tailored to a specific level of the user. More simpler explanations and examples are available in earlier chapters, compared to the later ones.
If something is unclear, you found a mistake, you would like more examples in the guide, or would like a feature covered, let me know!
The Guide currently covers all macros (as of SugarCube v.2.37.3), all functions and methods, and APIs. It touches upon the use of HTML, CSS, JavaScript and jQuery, when relevant. It also discusses aspects of accessibility.
The Guides also provides a list of further resources, for the different coding languages.
The Guide is available in a downloadable form for offline view:
HTML file that can be opened in Twine
.tw file that can be opened in Twine
source code, separating the chapters, .js and .css files
GITHUB REPO | RAISE AN ISSUE | TWINE RESOURCES TWEEGO | TEMPLATES | CSCRIPT 2 SG GUIDE
Twine® is an “an open-source tool for telling interactive, non-linear stories” originally created by Chris Klimas maintained in several different repositories (Twinery.org). Twine is also a registered trademark of the Interactive Fiction Technology Foundation.
SugarCube is a free (gratis and libre) coding format for Twine/Twee created and maintained by TME.
VIEW / DOWNLOAD THE GUIDE!!!!
As of this release (v2.0.0), it is up to date with the version 2.37.3. If you are looking for the guide covering SugarCube 2.36.1, you can find it on my GitHub.
Note: the Guide is now complete. There won't be further substantial updates.
505 notes · View notes
xemo-wc-08x · 3 months ago
Text
Website update
Hi there owo
Small update about my gallery website. I'd say it's... 90% done. XD
All the basic structure is done and now I have to add a few artistic details (images, stamps, gifs, dolls, changing some fonts...)
I wanted to add some hidden pages but... I'm unsure what to add o_O
So I guess I will leave it for a future page renovation u¬~¬
Once it's finished I'll make it public and I'll happily accept suggestions or ideas for the content :D
Also I have no coding experience apart from this website. I know the basics of html and css but I have no idea of javascript. If there's any mistake I'd also be glad to know. It's part of the reason why it's taking me so long ue.e
I'll be updating it each time I post drawings so that the gallery it's up to date.
Sneak peak~
Tumblr media Tumblr media
65 notes · View notes
syrupyy · 5 months ago
Text
end of an era (10/27/2021-01/07/2025)
Tumblr media
cookie run fans,
it is with sadness in my typing that I announce the end of the original (pre-Comic Studio) Cookie Comic Creator. the hosting company killed it b/c the debit card that was paying for it expired, and I completely did not see the payment failed notice in the flood of spam emails they send me every month - I have so much more I could say about why this company sucks, but point is I do not have all the files as they were before, and it would be too much hassle to bring it back when the site has been all but replaced with Cookie Run Comic Studio
if I don't forget to (and can find it all), I will add the last few changes I made to its code to github.com/syrupyy/cook... but, as it hasn't gotten new cookies or updates in a year+ anyways I just redirected it to Cookie Run Comic Studio, which is better and you really should be using it anyways...
thank you all for making comics with the stupid site I made for my friends to celebrate crob's 5th anniversary for so long HAHA. I know some people (in South Korea and China especially) still prefer CCC over CRCS, but the host has basically forced my hand here - and it's for the best IMO! we've put so much work into Comic Studio over the past two and a half years, and if you haven't tried it I highly suggest you do :')
also, it's worth mentioning that Comic Studio is doing great and is not going anywhere for as long as it pays my (and my friend and helper, illbloo's) bills. I keep daily backups of all its content, and HyperHimes has been keeping the Cookie Run studio up to date for me, so rest assured this will not affect anything on that front!!! we're also working on Scene Studio, and a whole bunch of other projects under a company I recently started - expect to hear more about that soon. for now though, we mourn the site that put us on the map; the idea that started it all with 600 lines of hastily assembled JavaScript.
(note: the official tag for posting comics on Tumblr will still be #cookie comic creator. this is for legacy reasons, but I also think it's cool to keep the original name going in spirit - you can always just set the panel size to Classic and pretend nothing has changed, after all!!)
so long and thanks for the unicorns, syrupyy
87 notes · View notes
dailypokemoncrochet · 9 months ago
Text
I think I've only had my website for like 3 weeks but I love it so much. Look I made a button for it too!
Tumblr media Tumblr media Tumblr media
I think I've figured out how I want the pokeamidex galleries to look, but now I have to consider whether I really want to have 2 separate galleries for each Pokemon. The Pokeamidex ones are going to be more detailed tho and look fancier and tie more directly into this as a project (like the dates that I made the Pokemon, blurbs about crocheting that specific pictured crochet), while the current galleries are just every picture I have for each Pokemon. I'm leaning towards two separate galleries even if it feels a bit redundant just because I want each to look a certain way that I can't reconcile if I put them together.
Still haven't figured out the random page thing because I think there's something I gotta do with javascript and or server and or arrays about it. The information is still stirring in my brain.
Not sure how to do the PC box with sprites thing either but I think it's going to end up being kind of like how some sites have little tamagotchis or pokewalker widget-y things, so I've been poking around those a bit. Is it going to be like a bunch of images of the PC boxes as a background, with a grid overlaid on it so I can arrange the sprites on it, and then coding for buttons to switch out the PC image box/sprite sets? To be learned!
Also I want to make a calendar showing what Pokemon I made on which days, like how I used to do in the beginning of this project (example) but none of these calendar code tips/tutorials are quite what I want. So that's also still swirling in my mind.
I think it's really funny that I will literally take breaks from crocheting for the project by doing stuff for the website for this project. Then I'll take breaks from the website by crocheting. You know this already but wow I really do think about crochet pokemon daily like all the time always. Which again is not news to anyone because I've literally crocheted more than 684 Pokemon at this point.
50 notes · View notes
idioticbat · 2 months ago
Note
i'm curious about something with your conlang and setting during the computing era in Ebhorata, is Swädir's writing system used in computers (and did it have to be simplified any for early computers)? is there a standard code table like how we have ascii (and, later, unicode)? did this affect early computers word sizes? or the size of the standard information quanta used in most data systems? ("byte" irl, though some systems quantize it more coarsely (512B block sizes were common))
also, what's Zesiyr like? is it akin to fortran or c or cobol, or similar to smalltalk, or more like prolog, forth, or perhaps lisp? (or is it a modern language in setting so should be compared to things like rust or python or javascript et al?) also also have you considered making it an esolang? (in the "unique" sense, not necessarily the "difficult to program in" sense)
nemmyltok :3
also small pun that only works if it's tɔk or tɑk, not toʊk: "now we're nemmyltalking"
so...i haven't worked much on my worldbuilding lately, and since i changed a lot of stuff with the languages and world itself, the writing systems i have are kinda outdated. I worked a lot more on the ancestor of swædir, ntsuqatir, and i haven't worked much on its daughter languages, which need some serious redesign.
Anyway. Computers are about 100 years old, give or take, on the timeline where my cat and fox live. Here, computers were born out of the need for long-distance communication and desire for international cooperation in a sparsely populated world, where the largest cities don't have much more than 10,000 inhabitants, are set quite far apart from each other with some small villages and nomadic and semi-nomadic peoples inbetween them. Computers were born out of telegraph and radio technology, with the goal of transmitting and receiving text in a faster, error-free way, which could be automatically stored and read later, so receiving stations didn't need 24/7 operators. So, unlike our math/war/business machines, multi-language text support was built in from the start, while math was a later addition.
At the time of the earliest computers, there was a swædir alphabet which descended from the earlier ntsuqatir featural alphabet:
Tumblr media
the phonology here is pretty outdated, but the letters are the same, and it'd be easy to encode this. Meanwhile, the up-to-date version of the ntsuqatir featural alphabet looks like this:
Tumblr media
it works like korean, and composing characters that combine the multiple components is so straightforward i made a program in shell script to typeset text in this system so i could write longer text without drawing or copying and pasting every character. At the time computers were invented, this was used mostly for ceremonial purposes, though, so i'm not sure if they saw any use in adding it to computers early on.
The most common writing system was from the draconian language, which is a cursive abjad with initial, medial, final and isolated letter shapes, like arabic:
Tumblr media
Since dragons are a way older species and they really like record-keeping, some sort of phonetic writing system should exist based on their language, which already has a lot of phonemes, to record unwritten languages and describe languages of other peoples.
There are also languages on the north that use closely related alphabets:
Tumblr media
...and then other languages which use/used logographic and pictographic writing systems.
Tumblr media
So, since computers are not a colonial invention, and instead were created in a cooperative way by various nations, they must take all of the diversity of the world's languages into account. I haven't thought about it that much, but something like unicode should have been there from the start. Maybe the text starts with some kind of heading which informs the computer which language is encoded, and from there the appropriate writing system is chosen for that block of text. This would also make it easy to encode multi-lingual text. I also haven't thought about anything like word size, but since these systems are based on serial communication like telegraph, i guess word sizes should be flexible, and the CPU-RAM bus width doesn't matter much...? I'm not even sure if information is represented in binary numbers or something else, like the balanced ternary of the Setun computer
As you can see, i have been way more interested in the anthropology and linguistics bits of it than the technological aspects. At least i can tell that printing is probably done with pen plotters and matrix printers to be able to handle the multiple writing systems with various types of characters and writing directions. I'm not sure how input is done, but i guess some kind of keyboard works mostly fine. More complex writing systems could use something like stroke composition or phonetic transliteration, and then the text would be displayed in a screen before being recorded/sent.
Also the idea of ndzəntsi(a)r/zesiyr is based on C. At the time, the phonology i was using for ntsuqatir didn't have a /s/ phoneme, and so i picked one of the closest phonemes, /ⁿdz/, which evolves to /z/ in swædir, which gave the [ⁿdzə] or [ze] programming language its name. Coming up with a word for fox, based on the character's similarity was an afterthought. It was mostly created as a prop i could use in art to make the world feel like having an identity of its own, than a serious attempt at having a programming language. Making an esolang out of it would be going way out of the way since i found im not that interested in the technical aspects for their own sake, and having computers was a purely aesthetics thing that i repurposed into a more serious cultural artifact like mail, something that would make sense in storytelling and worldbuilding.
Tumblr media
Now that it exists as a concept, though, i imagine it being used in academic and industrial setting, mostly confined to the nation where it was created. Also i don't think they have the needs or computing power for things like the more recent programming languages - in-world computers haven't changed much since their inception, and aren't likely to. No species or culture there has a very competitive or expansionist mindset, there isn't a scarcity of resources since the world is large and sparsely populated, and there isn't some driving force like capitalism creating an artificial demand such as moore's law. They are very creative, however, and computers and telecommunications were the ways they found to overcome the large distances between main cities, so they can better help each other in times of need.
13 notes · View notes
tofueatingwokerati · 4 months ago
Text
Tumblr media
The UK no longer has end to end encryption thanks to Keir Starmer’s Labour government reanimating the zombie policy that is the Snoopers Charter, first peddled by Theresa May’s Tory government and rejected by the public.
Apple withdrawing end-to-end encrypted backups from the UK "creates a dangerous precedent which authoritarian countries will surely follow".
UK now likened to authoritarian regimes and why Starmer won’t challenge Trump since he is in lock step with US policies, openly goes after sick, disabled, pensioners and poorest, increasing their hardship rather than tax the mega rich. US policy is UK policy.
So what does this mean for Apple users in the UK?
All your data in the cloud is no longer secure in comparison to having ADP enabled and can be accessed by the government upon request. The GDPR is all but dead in the UK, there are now so many government policies that snoop on us by the back door with even news outlets online now charging us for access without *cookies enabled (data farming you whilst you read with no option to opt out unless you pay)
I checked with the ICO myself and it is a fully approved policy despite its contradiction to the rights of consent, removed in the process.
If you want a workaround here are my suggestions
Cancel your iCloud storage, your data will stay on the cloud until the renewal date, use that time to back it up locally or on a flash drive.
Tumblr media
Change your iMessage settings to delete audio messages after 2 minutes and permanently delete messages after 30 days.
Alternatively, use a third party messaging app with a delete on read feature and disable Apple iMessage altogether.
If you are tech savvy you can set up a USB drive or flash drive directly into your router hub (you should have at least one USB slot, some have two) and use FTP to back up over wifi, you can do this on any device, you don’t need a desktop.
Use a VPN service or set one up. If you’re really technical you can use a Raspberry Pi to do this, but you will need to hard code it. Think Mr Robot.
This change does not impact sensitive data like medical details which remain end to end encrypted.
If you want to learn more on the sweeping bills being pushed through government and any action your can take visit Big Brother Watch: https://bigbrotherwatch.org.uk
*If you want to read news articles without paying for the privilege of not handing over your cookie data, simply disable javascript within your browsers settings and refresh the browser page. Remember to turn it back on when your done. Alternatively disable all cookies but know this will impact your online experience and access.
17 notes · View notes
robo-dino-puppy · 3 months ago
Text
I'm alive (theoretically)! I'm almost ready to start putting things up on the armor gallery <- view in a desktop browser for best results pls
the consensus from this post seems to be to keep the sky portion which is fine with me, but last call if you want to make your opinion known! next question:
Tumblr media Tumblr media
ok it's not super obvious when the pics are tumblr-sized, but any thoughts on if should I have the shield overlay not visible (left) or visible (right) on the shield-weaver? or both since there will be two images? no overlay with no headgear/visible with headgear maybe?
also I'd still love to find someone knowledgeable in current CSS/javascript/tumblr theme making (my CSS is many years out of date, I don't know js, and while I'm sure I could make a theme I simply don't have the spare brainpower to do it right now). the dropdown menus work on desktop but are iffy at best on mobile, and while I tried to make the theme* responsive to screen size changes, I'm sure it could be done better.
From what I understand of javascript (admittedly very little), a js dropdown menu would work much better on touchscreens - but if there's some sophisticated CSS that would also do the job I'd love to hear about it!
so if anyone wants to help me out in this area, I (and probably anyone who uses the armor gallery) would greatly appreciate it 🙏
*the theme I modified is like... ancient... and doesn't support NPF. which is not exactly a problem because before the old post editor went the way of the dinosaurs, I created *checks blog* 316 drafts in the old format. lol. lmao, even. I may not be good at planning but I AM good at hoarding! still, a theme that's up to current tumblr (and HTML/CSS) standards would be nice.
18 notes · View notes