Coding a Timezone Conversion Plugin for WordPress Using AI

Coding a Timezone Conversion Plugin for WordPress Using AI

There are a lot of claims that AI can replace developers, and so I wanted to see exactly what it was capable of. Based on my experiment, it is not there yet, but it is damn handy.

In this post, I want to run you through that experiment and show you exactly what AI (in my case, Claude 3.5 Sonnet) is capable of.

What I Was Looking to Achieve

I decided I wanted to build a simple WordPress plugin. I wanted it to take a shortcode and output the time in somebody’s local timezone.

So turn this:[timezone time="17:00" zone="Europe/London" into: "6PM Paris Time".

My Initial Prompt

I started by asking the following.

I want to work on a project. The goal is to create a WordPress plugin that takes a shortcode of a time and displays that time to the user in their local timezone. I was thinking the shortcode might look something like [timezone time="17:00" zone="Europe/London"] Are you ready or do you have questions?

It did indeed ask some questions:

  • Do you want the plugin to automatically detect the user's time zone? - To which I responded, "Yes."
  • Should the output format be customizable? - I decided to keep things simple, so I answered no.
  • Do you want to handle Daylight Saving Time (DST) changes? - In this case, I answered yes.
  • Do you have a preference for how to handle potential errors, such as invalid time formats or time zones? - I asked that it would just output the time shown in the shortcode.

First Attempt

Its first attempt completely sucked. It used PHP to look up the server time, rather than the local time of the client. However, when I pointed this out, it quickly changed approach.

It worked out that it could use Moment.JS to look up the timezone and do all the conversion work. It also wrote both the PHP and JS to make the plugin.

I downloaded the files individually, and I then zipped them up (for some reason it couldn’t zip them for me, unlike ChatGPT) so I could upload them to my website.

Unfortunately, it didn’t work.

Second Attempt

After telling Claude that things weren’t working, it attempted to guide me through some debugging using the developer tools in Chrome.

To be honest, this is the point where somebody with zero coding experience would give up. My coding skills are very rusty, and I only have a very rudimentary understanding of PHP and JavaScript. However, I am not intimidated by the console and other developer tools.

I uploaded a couple of screenshots from the developer tools, and it tried its best to work out the issue. In the end, I found that my browser was blocking the moment.js files. They were being loaded by a CDN, not served locally.

I explained the problem to Claude and it had its third attempt.

Third Attempt

This time it decided to install moment.js from the CDN locally when you install the plugin. This was fine, although this has a danger of breaking the plugin at some point in the future. However, for the purpose of this test I let it go.

It outputted the updated files, and I installed the plugin again. It still didn’t work.

Final Few Tweaks

Turns out we both made one dumb error each.

I failed to put the JavaScript file in the sub-folder it had specified. That was my bad.

Meanwhile, it had, for some reason, named that same file something completely different from the name it had specified in the code. That took me a while to spot, and it seemed oblivious to the fact too.

Once those issues were fixed, it finally worked. The entire exercise took about 50 minutes.

Conclusion

So can AI replace the need for a developer? Absolutely not. However, it does allow somebody with at least some development experience to do things that would previously have been out of reach to them.

But it is also dangerous. This test plugin could have security flaws, performance issues, or poor error handling that I might not know about.

Sure, I could probably ask Claude to help me identify and address them, but that relies on me being informed enough to know to ask.

We will still need experts to ask the right questions. AI will be just a handy tool for a while yet.

Because Somebody Will Ask

Finally, I know somebody will ask me to share the plugin, so here it is. Use it at your own risk!

Akhilesh Sunil Chaudhari

WordPress Developer | Shopify Developer | Freelancer | Wix Developer | Desktop Support Engineer | IT Executive | Learning DevOps | AWS & CI/CD Learner

7 个月

Great update!

回复

要查看或添加评论,请登录

Paul Boag的更多文章

社区洞察

其他会员也浏览了