Home / Internet Marketing News / Working With Dates & Times in Your Application

Working With Dates & Times in Your Application


I’ve been a professional developer for about six years now. During those six years I’ve never worked for a company or on a project that didn’t struggle with date and time issues in some form.

Nearly every application you will work on requires the use of time in some way, meaning that at some point you’re going to have to collect, store, retrieve and display dates or times. There’s no silver bullet for dealing with dates or times and you can never escape the inherent complexity that comes with our concept of time, but there are steps you can take to make it less of a pain.

In the years that I’ve been working with time across different programming languages, I’ve found the following knowledge goes a long way.

Choosing the Right Data Format

The first step when working with times and dates is to choose a representation for your data. While different formats may seem more or less the same, the format you choose will have a large impact on how you write and debug your code.

Using a numeric timestamp when you need a date will mean parsing the date timestamp and retrieving the date from that, which may or may not be straightforward depending on the time zone.

Using a custom string to represent a span of time seems easy to store and manipulate, but it’s difficult to query. Additionally, using any kind of representation that isn’t immediately recognizable by the human eye is going to make debugging your code more difficult.

When choosing a format for dates or times, I abide by the following rules:

  1. Never use numeric timestamps. They’re often the easiest to obtain by standard libraries among various programming languages but they’re not human readable and the temptation to manipulate them is too strong.
  2. Abide by ISO 8601, a standard that defines a format for date and time-related data. It’s trivial to find a library for any language that can handle the variations of ISO 8601.
  3. ISO 8601 is a standard, but it has many variations. You should always choose the most human-readable variant of ISO 8601. This requires no extra effort but makes debugging easier.
  4. Your timestamp string should only contain data you absolutely need. When working with times your string should not contain a date and when working with a date that is time zone-agnostic your string should not contain a time zone. Adding extra information adds ambiguity to the parsing operation and to the intent of the data for future developers
  5. When storing time zones always normalize to the same time zone in your timestamps. This not only makes it easier for a computer to sort and process the data but it makes it easier for a human developer as well.

Abiding by these rules won’t cost you much up front but they will make your life easier when your application is established and you find that your usage of times and dates isn’t what you expected.

Choosing the Right Tool

As with most problems in our industry, time and date handling comes down to picking the right tool for the job.

It’s tempting to use the tools in your favorite language’s standard library, but that might not be the best choice. While some standard libraries have fantastic date and time features (Python), others are downright pitiful (Javascript). Using the wrong tool makes it that much more difficult to develop features based around time and that makes it easier for bugs to slip into your application.

A good library for handling dates and times will allow you to follow the 5 rules mentioned above. Specifically, it should be able to:

  • Parse any date representation you may run into (including external representations.)
  • Output to any date representation you may need (including external representations.)
  • Manipulate dates and times by adding or subtracting units of time from them.
  • Compare dates and times.
  • Correctly convert between time zones.

It’s important that your library supports these features, otherwise the temptation to try to implement the functionality yourself will be too high. And just to be clear, if you try to implement any of that functionality yourself, you will fail.

Don’t parse your own timestamps with regular expressions, don’t add seconds to a numeric timestamp because it seems like a normal number and don’t compare dates and times using the equality operator. These libraries exist because these problems are hard to solve and reinventing the wheel in your application is just going to leave you with a broken wheel.

Below I have a few suggestions for libraries that fit these criteria:

Language  Library
Python  Standard Library
Javascript  Moment and Moment Time Zone
Java 8 and above  Standard Library (java.time)
Java 7 and below  Joda-Time
Swift  SwiftDate

If your language isn’t listed (because I’m not familiar enough with it) just search for <language> date and time library. Chances are you’ll find a good library that will do everything you need.

Knowing About Time

The final bit of knowledge I have to share isn’t specific to working with dates and times, but is more of a general philosophy to help us avoid problems and it applies to date and time handling as much as it does every other problem in programming.

Always check your assumptions.

We approach every problem presented with a large body of knowledge and an even larger body of assumptions. When handling dates and times it’s more important than ever to check your assumptions to ensure that they still hold for your scenario.

This list, titled Falsehoods Programmers Believe About Time, gives many excellent examples that illustrate time probably isn’t what you thought. When you’re designing or developing a feature that centers around time I encourage you to grab a partner and go through this list ensuring that you’ve avoided the pitfalls listed.

Time bugs are notoriously difficult to catch and even more difficult to test for. If you develop with this list in mind you may be able to avoid subtle bugs that would affect your customers but that they might not catch (the worst kind of bug!)

Time Zones

No discussion about times or dates would be complete without mention of time zones. In addition to familiarizing yourself with the common falsehoods listed above, also familiarize yourself with the basics of time zones.

Time zones will consistently be a pain point when working with time, even if you think you have them “all figured out”. Having a bit of knowledge about time zones will help you center your thinking and help ensure that you don’t make any logic errors when manipulating times.

Unfortunately there is no way to completely avoid the difficulty of storing and manipulating times and dates when programming. But if you follow these steps and work with this knowledge in mind, you can make the task easier by cutting down on the amount of code you have to write and forcing yourself into paradigms that are less likely to cause issues.

This post Working With Dates & Times in Your Application originally appeared on Sprout Social.

Click Here For Original Source Of The Article

Ads by WOW Trk

About Daniel Rodgers

A lot of news that you will not see in the paper. A lot of technology that is coming out that will not see in the paper.

Check Also

What Content Marketers Can Learn From an Adept Dungeon Master

Content Marketing Lessons from Dungeons & Dragons

Content Marketing Lessons from Dungeons & Dragons

It’s probably not news to you that 91% of B2B brands use content marketing to attract, engage, nurture, and convert their audience. However, it might be surprising to learn that only 9% of those brands rate their content marketing as “sophisticated.” Sophisticated meaning that their content marketing is successful, scales across the organization, and provides accurate measurement to the business. This puts a lot of pressure on content marketers to elevate their game and provide more worthwhile and valuable content experiences.

Patrick PinedaAs an adept Dungeon Master (DM) of Dungeons & Dragons (D&D) games, TopRank Marketing’s Motion Graphic Designer, Patrick Pineda, can relate.

It might sound a little odd at first, but Dungeon Masters and content marketers are more alike than you think. Responsible for creating meaningful and memorable experiences through content that takes people on a journey, you can see the similarities arise. Just like content marketers need to help guide people through the buyer journey, the Dungeon Master needs to guide players through a journey of their own.

After serving his friends as the go-to Dungeon Master, Patrick has learned a thing or two from creating lengthy campaigns—some successful, some not—that are both engaging and challenging. Discover Patrick’s lessons from the dungeon and how you can apply them to your content marketing campaigns and programs down below.

What Is a Dungeon Master?

For the unfamiliar, a Dungeon Master is the organizer for the wildly popular, 40-year-old tabletop role-playing game, “Dungeons & Dragons.” Not only do DMs organize the game, but they are also responsible for the game rules, details, and challenges. According to Patrick, the player experience hinges on a DM’s ability to create meaningful content that’s fun to explore.

One thing Dungeon Masters are not responsible for, however, are the players’ actions.

Like the self-directed buyers of today, D&D players are able to choose their own paths. As a result, DMs are challenged to make sure players finish the game. And just like your audience won’t read every piece of content you put in front of them, the same happens in a D&D game. Certain story elements DMs put together will never see the light of day because every player has a different play style, completes tasks in different orders, and takes different actions.

“The best Dungeon Master doesn’t just create a good story, but they also help players reach their goals,” Patrick claims.

Does any of this sound familiar? It certainly resonated for me.

5 Content Marketing Lessons From the Dungeon

Having created D&D campaigns that ruled and bombed, here are Patricks top five tips for developing content that resonate with your audience.

#1 - Your audience values originality.

If Patrick creates a campaign that plays to common tropes like a damsel in distress or small town disappearances, the story becomes predictable. But worse than that, the players feel condescended to as the game starts to feel dumbed down.

“Cliches and stereotypes will make players groan. It’s important when creating a campaign that I shake it up and play against common conventions,” Patrick says.

When examining your content and the story you’re trying to tell, it’s just as important to stay original and play with your audience’s expectations. For example, listicles with social media tips are a dime a dozen. Your audience might be more interested if you flip the idea on its head with social media mistakes. In changing it up, you’re giving your audience something new that they haven’t read before, capturing their interest.

[bctt tweet="When examining your content & the story you’re trying to tell, it’s just as important to stay original & play with your audience’s expectations. - @aleuman4 #ContentMarketing" username="toprank"]

#2 - Appeal to curiosity.

When it comes to creating an adventure for players to navigate, the DM has a seemingly impossible job. They need to create a unique and compelling world that is able to hold players’ attention—something not easily done. In fact, campaigns have taken Patrick days to put together. But that doesn’t come without its drawbacks.

“I’ve spent hours upon hours creating content for a campaign. But 80% of what I create may never see any playtime. It’s ultimately the players’ choice as to what tasks they want to complete and what quests they want to go on,” Patrick points out.

While the D&D world needs to have a unique and compelling narrative, it also needs to appeal to a player’s curiosity to ensure they keep playing the game and play the parts of the game that you want them to.

How does this apply to content marketing? Well, as you know, just because you’re producing content, doesn’t mean that your audience will find it. To find the answers they’re looking for, they might scour the internet, social media, and trusted experts for more information. Having an integrated content strategy that has multiple touch points throughout the buyer journey and an omni-channel approach, helps ensure you’re reaching your target audience whenever and wherever they may be searching.

Weaving SEO, social media, and influencer marketing into your content marketing strategy helps improve the reach and engagement of the content you’re producing. Through SEO, your organic rankings and click-through-rates will start to rise, improving your organic traffic. Social media messages that are well written and value-based help attract larger audiences from their social feeds. And, finally, tapping into industry influencers exposes your content to a wider network of like-minded individuals, as well as adding authority and credibility.

#3 - Avoid corraling your audience.

Nobody likes to be told what to do, including D&D players. While the DM writes the game and serves as a referee, they cannot influence a player’s actions. And if a DM attempts to, they could quickly lose a player’s interest.

“As a DM, it can be tempting to intervene and make sure that your players are playing the game the way you intended. But this is the one thing you cannot do.” Patrick emphasizes.

This is true in content marketing, too, as making calls to action (CTAs) with zero context can be a turn-off for your audience. If you insert a CTA before your audience can learn what’s in it for them, whether it’s downloading an eBook, listening to a podcast, or subscribing to your blog, they’re less likely to do it. In fact, QuickSprout found that placing a CTA above the fold on a page decreased their conversion rate by 17% and attributed it to their audience not fully understanding why they should complete the action.

Instead, make sure that your CTAs have plenty of context and explain what the audience will gain by filling out your form, reading another blog post, etc. This helps ensure that your content satisfies your audience’s quest for knowledge.

#4 - Customize content for your audience, not the other way around.

As we mentioned previously, the players are in charge of their actions and how they choose to play the game, making it impossible for DMs to have control over the game experience. This makes it important for DMs to know their audience ahead of time, so they can include important sought-after details into different game components.

“I’ll ask players before we start what they hope to get out of the game, whether it’s take down an enemy or just to have fun. Knowing this ahead of time, I can tailor the game to what each player wants to have happen,” Patrick says.

For content marketers, this lesson should hit close to home. You need to know your audience well in advance in order to deliver personalized content. If you create content and worry about your audience later, chances are you aren’t engaging the right people.

After taking a look at your own audience’s characteristics and interests in Google Analytics, create unique personas for each of your audience members. This allows you to create content that is tailored for each person you hope to attract and engage. For example, if one of your target personas is a Director of Business Development, creating custom content that addresses a unique pain points like identifying new business opportunities or tips from the experts on how to strengthen their existing client relationships.

[bctt tweet="If you create content and worry about your audience later, chances are you aren’t engaging the right people. - @aleuman4 #ContentMarketing" username="toprank"]

#5 - Chart your course.

There is a lot going on in a D&D game. And for the DM, that number is amplified as you have to remember every detail about your players, what’s been completed, and what could come next.

“To make sure I’m on top of the game and can portray characters well, I chart the game’s relationships instead of story elements. If I focus on the story, it could quickly become useless as players might do things out of order or in a non-linear fashion. By focusing on the relationships and where they fit in the narrative, the game becomes more fluid and flexible for the players and I can keep track of their journey,” Patrick says.

Tracking the journey isn’t the only thing Patrick notes, however. He also documents player strengths, weaknesses, and stats as the game progresses.

“I keep a character sheet that details each player’s play style. For example, if a player is investing their skill points in intelligence, I can tailor future encounters in the game to focus on problem-solving instead of combat. The opposite is true for a player who invests in raw strength,” Patrick notes.

Through detailed charts, maps, and grids, Patrick is able to make sure that his players have a personalized, seamless experience for every campaign they play, regardless of how they play it.

Customer Journey & Dungeons and Dragons Journey

By taking the same approach with your content marketing, you can identify opportunities for customization and develop a strategy for weaving your content into the buyer’s journey. For example, by knowing which pieces of content attract a larger audience or drive more conversions, you can use that information to inform your content development and map your content to different stages of the funnel (see below).

Grid Assigning Content to Buyer Stages

To collect this data on your content and audience, review your Google Analytics behavior and conversion dashboards to find our which pieces of content excel at attracting, engaging, or converting your audience. Metrics like page views and entrances are good indicators for attraction, whereas time on page or number of pages per session can help you understand engagement. And, finally, the number of conversions through conversion tracking is the best way to find your top converting content. Armed with this knowledge you can create content plans that are tailored for your audience’s unique buyer journey.

Your Audience Is the Hero

A good Dungeon Master enables players to become the hero of the story through a personalized game with a compelling, original narrative. As a content marketer, it’s your responsibility to create content that transforms your audience into heroes as well, helping them solve seemingly impossible problems with your expert, best-answer advice.

Through an integrated content strategy with originality, personalization, and “best answer” content that’s mapped to the buyer journey, you can become the perfect Content Master for your audience.

For more ideas on how to become a masterful content marketer, check out these 25 content marketing tips, including how to tackle writer’s block, repurpose content, utilize storytelling, and more.

The post What Content Marketers Can Learn From an Adept Dungeon Master appeared first on Online Marketing Blog - TopRank®.

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php