GMT time conversion to Unix epoch

558fe5180e0e8fc922d31c23ef84d240

I am trying to convert the GMT time into unix epoch (starting from 1970), looks like there is a small bug
in code , i could not get and exhausted.

I see following difference

Non leap years
Expected output: Jan 20 19:00:01 2019 GMT = 1548010801
Actual output: 1548097201 (which is Jan 21 19:00:01 2019 GMT, 1 day difference)

Leap Year
Expected output: Dec 27 14:52:30 2020 GMT = 1609080750

Actual output: 1609253550 (which is Dec 29 14:52:30 2020 GMT, 2 days difference)

I really appreciate any help in finding the problem.

`
#include <stdio.h>
#include <string.h>
#include <time.h>

#define BASE_YEAR 1970

void print_time_readable_format(struct tm tm);
int convert_gmt_date_time_to_tm_format(char* gmt_time_fmt);
int check_year_is_leap_or_normal(int year);
int get_number_of_leap_years_from_base_year(int start_year, int end_year);
int convert_gmt_to_epoch(struct tm tm);

int main()
{
    int epoch = 0;
    //char gmt_time_fmt[] = "Jan 20 19:00:01 2019 GMT";
    //char gmt_time_fmt[] = "Dec 27 14:52:30 2020 GMT";
    char gmt_time_fmt[] = "Jan 01 00:00:00 1970 GMT";
    epoch = convert_gmt_date_time_to_tm_format(gmt_time_fmt);
    printf("time in GMT = %s and epoch is %d\n", gmt_time_fmt, epoch);

    return 0;
}

int convert_gmt_date_time_to_tm_format(char* gmt_time_fmt)
{
    struct tm tm;
    char tm_time_fmt[255];

    //set tm struture to 0
    memset(&tm, 0, sizeof(struct tm));
    // convert gmt_time_fmt to format required by 'tm' structure
    strptime(gmt_time_fmt, "%B %d %H:%M:%S %Y GMT", &tm);

    strftime(tm_time_fmt, sizeof(tm_time_fmt), "%s", &tm);
    printf("tm_time_fmt = %s\n", tm_time_fmt);

    print_time_readable_format(tm);

    return convert_gmt_to_epoch(tm);

    return 0;
}

int convert_gmt_to_epoch(struct tm tm)
{
    int days_by_month [2][12] = {
        /* normal years */
        { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
        /* leap years */
        { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
    };

    int current_year = tm.tm_year+1900;

    printf("current_year =%d\n", current_year);

    int total_years_passed = current_year - BASE_YEAR;

    printf("total_years_passed =%d\n", total_years_passed);

    int nleap_years_passed = get_number_of_leap_years_from_base_year(BASE_YEAR, current_year);

    int normal_years = total_years_passed - nleap_years_passed;

    printf("normal_years =%d\n", normal_years);

    int total_days_passed = (normal_years*365 + nleap_years_passed*366 );

    printf("total_days_passed =%d\n", total_days_passed);

    total_days_passed += days_by_month[check_year_is_leap_or_normal(current_year)][tm.tm_mon];

    printf("total_days_passed after adding month =%d\n", total_days_passed);

    total_days_passed += tm.tm_mday;

    printf("total_days_passed after adding day =%d\n", total_days_passed);

    total_days_passed  = total_days_passed*24 + tm.tm_hour;
    total_days_passed  = total_days_passed*60 + tm.tm_min;
    total_days_passed  = total_days_passed*60 + tm.tm_sec;

    printf("total_days_passed final =%d\n", total_days_passed);

    return total_days_passed;

}

int get_number_of_leap_years_from_base_year(int start_year, int end_year)
{
    int leap_year_count = 0;
    int year = start_year;

    while( year <= end_year)
    {
        if(check_year_is_leap_or_normal(year))
            leap_year_count++;
        year++;
    }

    printf("leap_year_count = %d\n", leap_year_count);

    return leap_year_count;
}

int check_year_is_leap_or_normal(int year)
{
    if( ( year%4 == 0 ) && ( ( year%400 == 0 ) || ( year%100 != 0)))
         return 1;
    else
        return 0;
}

void print_time_readable_format(struct tm tm)
{
    printf("tm.tm_year = %d ", tm.tm_year);
    printf("tm.tm_mon = %d ", tm.tm_mon);
    printf("tm.tm_mday = %d ",tm.tm_mday);
    printf("tm.tm_hour = %d ", tm.tm_hour); 
    printf("tm.tm_min = %d ", tm.tm_min );
    printf("tm.tm_sec = %d\n", tm.tm_sec );
}
`

Top 10 APIs for Museums

Featured Imgs 23

It seems that almost every discipline imaginable is undergoing a digital transformation these days. That includes the art, science, and culture world of museums.

Connecting 2 outers to the same CPU

Category Image 041

Hi, the DSL had intermittent problem. The service provider came and fixed the problem.

As a result of the brief problem, my Netgear N600 WIFI Range Extender ceased connecting to the Internet via WIFI DSL modem (internet light won't turn on). I have done all the requirements including factory reset, power off, etc. to no avail. My other wireless devices(cell phones) which use to operate normally with the Netgear are unable to communicate to the Netgear either.

My Desktop CPU has only 1 Ethernet port which I currectly use to connect the CPU to the DSL. I am unable to connect the Netgear to the CPU as well.

Please advise. Thank you.

A Calendar in Three Lines of CSS

Category Image 052

This article has no byline and is on a website that is even more weirdly specific than this one is, but I appreciate the trick here. A seven-column grid makes for a calendar layout pretty quick. You can let the days (grid items) fall onto it naturally, except kick the first day over to the correct first column with grid-column-start.

Thoughts:

  • I’d go with an <ol> rather than a <ul> just because it seems like days are definitely ordered.
  • The days as-a-list don’t really bother me since maybe that makes semantic sense to the content of the calendar (assuming it has some)
  • But… seeing the titles of the days-of-the-week as the first items in the same list feels weird. Almost like that should be a separate list or something.
  • Or maybe it should all just be a <table> since it’s sort of tabular data (it stands to reason you might want to cross-reference and look at all Thursdays or whatever).

Anyway, the placement trickery is fun.

Here’s another (similar) approach from our collection of CSS Grid starter templates.

Direct Link to ArticlePermalink


The post A Calendar in Three Lines of CSS appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

How to Add Additional User Profile Fields in WordPress Registration

Category Image 091

Do you want to add extra profile fields for users to fill in when they register on your WordPress website?

Maybe you want to allow users to submit their social media profiles. Or you might want them to submit their business phone number when registering. This can all be done by adding additional profile fields.

In this article, we will show how to easily add additional user profile fields in WordPress registration forms.

Adding additional user profile fields in WordPress registration

Why Add Additional User Profile Fields in WordPress Registration?

By adding more user profile fields to your WordPress website’s registration form, you can collect extra information from users to improve your marketing campaigns, personalize content, or simply learn more about your audience.

For example, you can ask your users to provide their phone numbers or social media profiles when registering on your WordPress site.

This way, you will be able to send targeted SMS messages to your users or can ask them to promote your WordPress blog on their social media accounts.

All of these extra fields can be handy if you run a membership website or allow users to sign up as subscribers to your blog. They can also be helpful if you want to store extra contact information for the other writers on your multi-author blog.

That being said, let’s see how to easily add additional user profile fields in WordPress. For this tutorial, we will be discussing two methods, and you can use the links below to jump to the method of your choice:

Method 1: Add Custom User Profile Fields Using Advanced Custom Fields (Recommended)

The best way to add extra user profile fields in WordPress is to use the Advanced Custom Fields plugin. It lets you choose from multiple fields and customize them to fit your needs.

First, you need to install and activate the Advanced Custom Fields plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you need to head to the ACF » Field Groups page from the WordPress admin sidebar and click the ‘+ Add Field Group’ button.

Click the Add Field Group button

This will take you to a new page where you can start by typing a name for the field group.

Keep in mind that this will be the name of the entire field group and not the individual user’s field.

Type field group name

After that, scroll down to the ‘Fields’ section and choose a field type from the dropdown menu.

For example, if you want users to provide their phone number upon registration, then you can choose the ‘Number’ option. Alternatively, if you want users to provide their social media profiles, then you can pick the ‘Text’ option.

Choose a field type from the dropdown menu

Once you have done that, just type the name of your field into the ‘Field Label’ option. For instance, if you want users to provide their Twitter handle before registering, then you can enter that into the field.

The plugin will then automatically generate a field name according to your label name.

Add field name and label

Next, you must switch to the ‘Validation’ tab from the top. From here, you can make the field required by toggling on the switch. This way, users won’t be able to register on your WordPress site without filling in the additional field.

After that, you can even set a character limit for your custom field.

Toggle the Required switch for the additional field

Now, switch to the ‘Presentation’ tab from the top.

Once you are there, you can add placeholder text, instructions, and wrapper attributes for your additional user profile field.

Configure the Presentation settings

Next, scroll down to the ‘Settings’ section and make sure that the ‘Location Rules’ tab is selected. From here, you must set up conditional logic for your custom field so that it will only be displayed for your WordPress site registration.

To do this, select the ‘User Form’ option from the dropdown menu in the left corner of the screen. After that, choose the ‘Register’ option from the dropdown menu in the right corner.

Add conditional logic for the additional user field

Finally, click the ‘Save Changes’ button at the top of the screen to store your settings.

If you want to add another additional field, then you can also click the ‘+ Add Field’ button.

Save the additional field

Now visit your user registration page to view the additional user profile field in action.

This is how it looked on our demo website.

Preview for additional user profile field

Method 2: Add Additional User Profile Fields With Profile Extra Fields (Easy & Simple)

This method allows you to quickly and easily add extra fields to user profiles and user registration forms in WordPress. It is a little less flexible, but it gets the job done.

First, you need to install and activate the Profile Extra Fields plugin. If you are not sure how to do this, then you can check out our full guide on how to install a WordPress plugin.

Once the plugin is activated, it’s time to create some additional user profile fields to use on your registration forms.

We are going to create a phone number field as an example, but you can add as many of these fields as you want.

First, visit the Profile Extra Fields » Add New page from the WordPress admin sidebar. From here, type the name of the field next to the ‘Name’ option.

For example, if you are creating a field for users to submit their phone number, then you can type ‘Phone Number’ as the field name.

After that, select a field type from the dropdown menu. If you are adding a social media profile field, then you can use the ‘Text Field’ option.

However, if you want a field for phone numbers, then you need to select that option from the dropdown menu.

Add field name and type

After that, you can also type a pattern for your phone number field or add a description for it.

Next, scroll down to the ‘Field Properties’ section and check the boxes for the user roles that you want this field to be displayed for.

For instance, if you want this field to be displayed for all the authors registering on your WordPress site, then you can check the box next to this user role.

You can choose as many user roles as you want.

Configure field properties

Next, you can also check the ‘Required’ box if you don’t want users to register without filling in this field in the form. Make sure that the ‘Always Show in User Registration Form’ box is checked so that your user field will be displayed in the form.

Finally, click the ‘Save Changes’ button to store your settings.

Check the box to show the field in user registration form

Now, you will need to go into your WordPress dashboard to change some settings for new registrations.

Head to the Settings » General page in your WordPress admin area and then check the membership box so that anyone can register on your website.

Next, you need to make sure that the default role is set to the role which you have added extra fields for. After that, click the ‘Save Changes’ button to store your settings.

Set user default role

This way, you can control the level of access new users have, and this will force the registration form to show the fields you selected earlier in this tutorial.

Here’s what the default registration form looked like on our demo website.

Preview for the user field in registration form

Bonus: Make a Custom User Registration Form in WordPress

The methods in this tutorial have shown you how to add extra user profile fields to the default WordPress registration form.

However, if you would like to create a custom user registration form in WordPress, then you can also easily do that by using the WPForms plugin.

It is the best WordPress form plugin that allows you to design your own user registration form using drag and drop. It also integrates seamlessly with plugins like Advanced Custom Fields, so you can easily insert additional user profile fields.

Edit user registration form

For detailed instructions, please follow our tutorial on how to create a custom user registration form in WordPress.

We hope this tutorial helped you learn how to add additional user profile fields in WordPress registration. You may also want to see our beginner’s guide on how to create a custom WordPress login page and our comparison of the best WordPress membership plugins to create and sell courses.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Add Additional User Profile Fields in WordPress Registration first appeared on WPBeginner.

“Yes or No?”

Category Image 052

Sara Soueidan digs into this HTML/UX situation. “Yes” or “no” is a boolean situation. A checkbox represents this: it’s either on or off (uh, mostly). But is a checkbox always the best UX? It depends, of course:

Use radio buttons if you expect the answer to be equally distributed. If I expect the answer to be heavily biased to one answer I prefer the checkbox. That way the user either makes an explicit statement or just acknowledges the expected answer.

If you want a concrete, deliberate, explicit answer and don’t want a default selection, use radio buttons. A checkbox has an implicit default state. And the user might be biased to the default option. So having the requirement for an explicit “No” is the determinig factor.

So you’ve got the checkbox approach:

<label>
  <input type="checkbox">
  Yes?
</label>

Which is nice and compact but you can’t make it “required” (easily) because it’s always in a valid state.

So if you need to force a choice, radio buttons (with no default) are easier:

<label>
  <input type="radio" name="choice-radio">
  Yes
</label>
<label>
  <input type="radio" name="choice-radio">
  No
</label>

I mean, we might as well consider another a range input too, which can function as a toggle if you max it out at 1:

<label class="screen-reader-only" for="choice">Yes or No?</label>
<span aria-hidden="true">No</span>
<input type="range" max="1" id="choice" name="choice">
<span aria-hidden="true">Yes</span>

Lolz.

And I suppose a <select> could force a user choice too, right?

<label>
  Yes or no?
  <select>
    <option value="">---</option>
    <option value="">Yes</option>
    <option value="">No</option>
  </select>
</label>

I weirdly don’t hate that only because selects are so compact and styleable.

If you really wanna stop and make someone think, though, make them type it, right?

<label>
  Type "yes" or "no"
  <input type="text" pattern="[Yy]es|[Nn]o">
</label>

Ha.


The post “Yes or No?” appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

Voice Search and What It Means for Your WordPress Site

Featured Imgs 26

From as early as 2016, experts have been predicting that voice searches will eventually make up a significant percentage of Google searches worldwide. Now that more people are using smart devices such as Google Home, Alexa, and Siri at home, voice search capability is becoming less of a novelty and more of a must-have for […]

The post Voice Search and What It Means for Your WordPress Site appeared first on WPExplorer.

​Sendbird Announces Chat Platform Enhancements

Featured Imgs 23

Sendbird, a chat and messaging services provider, has announced several updates to its chat offerings that the company hopes will allow developers to better adapt to a communication environment that has been reshaped by COVID-19. These Updated include new partitioning options for Open Channels, IP whitelisting, and message threading. 

How to Create Featured Images That Draw More Readers to Your Blog

Fotolia Subscription Monthly 4685447 Xl Stock

This post is originally published on Designmodo: How to Create Featured Images That Draw More Readers to Your Blog

How to Create Featured Images That Draw More Readers to Your Blog

You’re familiar with how valuable images are on a website. They can: Break up otherwise long stretches of text. Visually complement the content on a page. Reinforce a brand’s visual identity and style. Simplify how many words are used to …

For more information please contact Designmodo

can someone help me with this code.

558fe5180e0e8fc922d31c23ef84d240

Write a program simulator that will compute for the average waiting time of each customer in a bank. Also the program will indicate the number of the teller who accomodates the customer.

Assume that the bank has 3 teller that may be accomodate the customers. The first customer to arrive will be served by teller 1 and the arrival time is zero(0). The second customer will be served by teller 2, the third customer by teller 3, the fourth customer will be served by the any teller who is already free and so on. The bank is using FIFO in serving their customers.

The length of service depends on the type of service the customer will avail. Services available in the bank are:
Deposit - 5 minutes
New accounts - 8 minutes
Withdrawal - 3 minutes
Check encash - 4 minutes

The program should reord the arrival time of each customer. For simplicity, assumed that the arrival time is in minutes. Again, the first customer will always have an arrival time of 0. Eliminate the concept of several clients that will arrive at exact;y the same time.

The program should be abale to determine the number of customers each teller accommodated.

The waiting time is computed as the time the service is started minus arrival time of the customer. For example, the first customer arrives at 0 and the service also started at time 0 since there is no queque yet. So, the waiting time for customer 1 is 0. If customer 2 arrives at time 5, he will be the first customer for teller 2. The service time will also start at time 5 thus, the waiting time of customer 2 is also 0.

Assume that the bank can serve 20 customers at the most.

Optimizing Image Depth

Featured Imgs 23

Something I learned (or, I guess, re-learned) this year is how important it is to pay close attention to the bit depth of images. Way back in the day, we used to obsessively choose between 2-, 4-, or 8-bit color depth on our GIFs, because when lots of users were using dialup modems to surf the web, every kilobyte counted.

Now that a huge number of us access the web via broadband, guess what? Every kilobyte still counts. Because not everyone has access to broadband, particularly in the mobile space; and also, any time we can shave off page rendering is worth pursuing. I’d assumed that optimization tools handled things as trivial as color depth optimization that for us, but discovered I was wrong there.

This is particularly true for PNGs.  By default, lots of image editing tools save PNGs with 2^24 color depth, just in case.

For a photograph, that makes some sense (though if it’s a photograph, you should probably save it as JPG or WebP) but for things like logos and icons, that’s approximately 2^24 more colors than you’re going to be using.

So in Acorn, my image editor of choice, I’ve been taking special care to crank down the bit depth on PNGs in the export dialog. In many cases, I’ve cut image weight 80% or more by indexing colors to a palette of 256 or fewer values, with no loss of visual fidelity.  (Again, these aren’t photographs I’m talking about.)

Here’s an example:

PNG export from Acorn

That PNG at full-color depth is about 379KB. Restricted to a palette of 32 colors, it’s 61KB. And that’s just at the export time: once I run them through ImageOptim, the optimized sizes are 359KB and 48KB. That’s a weight savings of about 85%, just by lowering the color depth. And if I deployed the image and discovered it needs a few more colors, I could re-run the process to use 64 colors: the final size, in that case, is 73KB, still enormous savings.

Image run through ImageOptim, reducing size by another 22%

Reducing color depth by eye is clearly more onerous than throwing an optimization script at a directory of images, but in my experience, the results are much more efficient in terms of image weight and therefore user experience. And that’s really what all this is about, isn’t it?


The post Optimizing Image Depth appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

What Makes CSS Hard To Master

Featured Imgs 23

Tim Severien:

I feel we, the community, have to acknowledge that CSS is easy to get started with and hard to master. Let’s reflect on the language and find out what makes it hard.

Tim’s reasons CSS is hard (in my own words):

  • You can look at a matching Ruleset, and still not have the whole styling story. There might be multiple matching rulesets in disparate places, including in places that only apply conditionally, like within @media queries.
  • Even if you think you’ve got a complete handle on the styling information in the CSS, you still may not, because styling is DOM-dependent. You need information from both places to know how something will be styled.
  • You have no control over the device, browser, version, resolution, input mode, etc., all of which can be CSS concerns.
  • Making changes to CSS can be scary because it’s hard to understand everywhere it applies.

I’m not sure people making sweeping generalizations about CSS either being too hard or too easy is helpful for anyone. It’s much more interesting to look at what can be straightforward about CSS and what can be tricky, like Tim has done here.

Direct Link to ArticlePermalink


The post What Makes CSS Hard To Master appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

Contact Form 7 Version 5.3.2 Patches Critical Vulnerability, Immediate Update Recommended

Category Image 091

Contact Form 7 has patched a critical file upload vulnerability in version 5.3.2, released today by plugin author Takayuki Miyoshi. The plugin is installed on more than five million WordPress sites.

“An unrestricted file upload vulnerability has been found in Contact Form 7 5.3.1 and older versions,” Miyoshi said. “Utilizing this vulnerability, a form submitter can bypass Contact Form 7’s filename sanitization, and upload a file which can be executed as a script file on the host server.”

The vulnerability was discovered by Jinson Varghese Behanan from Astra Security on December 16, 2020, and Miyoshi released a fix less than 24 hours later. Behanan highlighted a few ways this vulnerability might be exploited:

  1. Possible to upload a web shell and inject malicious scripts
  2. Complete takeover of the website and server if there is no containerization between websites on the same server
  3. Defacing the website

Astra Security plans to publish more details on the vulnerability in two weeks after the plugin’s user base has had more time to update to the patched version.

Version 5.3.2 removes control, separator, and other types of special characters from the filename to fix the unrestricted file upload vulnerability. At the time of publishing, more than a million Contact Form 7 updates have been downloaded today. Approximately 20% of the plugin’s user base is protected from the vulnerability. Now that it has been patched and published, Contact Form 7 users who do not update will be more at risk of having the vulnerability exploited.