Authoranvyst

CakePHP Time formatting: year of “week of year”

While jumping between PHP and JavaScript – one of the most annoying things is dates handling.

Recently, one of the clients reported that, while using our app for appointments and work schedule – they lost one of the working days. Client’s worker was supposed to work on the 31st of December 2019.

Firstly, working on the 31st is an achievement. Since we can’t affect it, “bug report” was filled on our end. After few hours of debugging, the problem was found.  

CakePHP uses Cake\I18n\Time class to handle date time. It’s an ancestor of chronos library under the hood. As a result, when you’re working with DateTime object, the formatting slightly changes. Thankfully, I was not the only one who accidentally used “year” notation wrong. 

use \Cake\I18n\Time;

$badDayToWork = '2018-12-31 09:00:00';
$time = new Time($badTimeToWork);

print_r($time);
/*
output:
Cake\I18n\Time Object(    
    [time] => 2018-12-31T09:00:00+02:00    
   [timezone] => Asia/Nicosia    
   [fixedNowTime] =>
)
*/

print_r($time->i18nFormat('YYYY-MM-dd HH:mm'));

// Output: 2019-12-31 09:00.

One tiny bit I missed was incorrect “Y” formatting flag.

yyyy (year)
2018
YYYY (year of “Week of Year”)2019

In this case, 2018-12-31 falls on Monday, so according to ICU documentation – it’s year 2019.

Code Churn: post-release defect elimination

Among numerous metrics on code evaluation (like CRAP index) in product lifecycle, code churn seems to be the one to look for while dealing with post-release and legacy code elimination.

Code churn helps you to evaluate file changes across builds.

 Code churn is a good predictor of post-release defects. Thus, it’s a warning sign if you approach a deadline while your code churn increases. That’s a sign that the code gets more and more volatile the closer you get to your deadline. You want the opposite. You want to stabilise more and more code the closer you get to delivery.

Codescene

Code Churn features

One of the features of code churn – is bottleneck finding across developers and tasks. Low commit rates per author can signal the management, that there’s some sort of problem going on:

  •  Task ambiguity that prevents to complete the task, indecisive stakeholders
  • Technical issues within the platform, preventing on completing the task
  • Legacy code that remains in the product, and possible technical debt increase
  • Under-engagement

Ben Thomson in his post about code churn, provides few graphs, illuminating code impact on productive/churn code across release cycle. As an example, I’ve used CodeScene service, to test code churn on one of the plugins I’ve worked a lot back in the days (hopefully will have time to get back to it soon) – cakephp-calendar.

Calendar Sample

cakephp-calendar code churn graph

As we can see, March-April was a major rewrite of the plugin, that followed next spike occurring in July.  March re-write made the code more fragile. If we dig deeper, we can see that an overall complexity of March-April release was drastically decrease. Here’s one of the examples:

complexity graph of CalendarsTable.php

It’s still quite high, but it’s nothing comparing to what it was. Still, the code was in semi-prototype mode.

Apart of CodeScene service, there’s a specific churn-code composer package for PHP-based projects, that might be more useful for developers.

Dashboards with GraphQL & ElasticSearch

Here’s an example of creating Dashboards with GraphQL and ElasticSearch from React community.

As a big fan of VueJS framework, it’s still nice to check what’s happening on the other side of the fence from React community fellow coders. 

Mitch Clay published an article on how you can utilise GraphQL with ElasticSearch to design dashboards for the your projects.

The stack is pretty common for JS environment:

  1. NodeJS
  2. React
  3. GraphQL with Apollo

But, the only bit I missed using – ElasticSearch engine, as more and more projects use it – it seems that I need to give it another look.

AdminLTE Midnight theme: customising templates

AdminLTE is by far one of the great examples of what Bootstrap CSS can do and consists of pre-defined UI elements used for Admin control panels. Similarly we have ElementUI, Bulma, and Bootstrap CSS in its core. 

Right now, there’s a massive amount of various admin panels on the net.

AdminLTE Midnight Theme
AdminLTE Midnight Theme

So, I made a quick Proof of Concept on how we can easily convert default AdminLTE layout into a dark theme, with a bit of help from grunt and yarn.

AdminLTE Midnight Dark Theme is available on GitHub. I added a detailed description on how to run it in dev mode via AdminLTE repository.

You might find it useful to go through customisation instructions first.

VueJS.London – Jest for Vue testing

Images Copyright www.edtelling.com

In September, I was lucky to attend VueJS London conference. It was an amazing experience, with lots of interesting talented people from different corners of the EU and the States.

I’ll slowly start assembling the info on the talks that took place there. Once the slides become available I will start adding them here as well.

One of the greatest talks at the conference was by Roman Kuba. It was about test utils for VueJS, and actual experience on integrating Jest for Vue infrastructure.

Qobrix is slowly integrating VueJS as a sidekick for all the sophisticated UI/UX solutions, trying to reduce jQuery impact on the platform. One of the reasons behind a slow pace of integration – kind of frustrating situation with plethora of test tools.

Quick googling on the subject, brings some more structured materials from Roman, on VueJS/Jest integrations and how they do it in CodeShip.

One of the things that’s definitely worth checking – vue-test-utils.

© 2018 Andy's Cave

Theme by Anders NorénUp ↑