Jump to content

Module: FieldtypeTime & InputfieldTime


netcarver

Recommended Posts

Am I right that this field cannot be used in a FormBuilder form? I'm trying to make a form with a start and stop button to calculate time students spend on one of our lasercutting machines. 

[edit] In the meantime I found it. Now I just wanted to know if I can have the time 'auto fill in' in a field 'laser_start' as soon as a new form is created, like I can with a Datetime field. And also have a button or picker to enter the time in a field 'laser_stop' when I edit the page created by Formbuilder.

Another issue: the Time Format always jumps to 'Minutes (00-59) & seconds (00-59).' when I choose 'Hours (0-24), Minutes (00-59) & seconds (00-59)' upon save in the Details tab.

Link to comment
Share on other sites

  • 1 month later...
On 12/30/2018 at 12:38 PM, BFD Calendar said:

Another issue: the Time Format always jumps to 'Minutes (00-59) & seconds (00-59).' when I choose 'Hours (0-24), Minutes (00-59) & seconds (00-59)' upon save in the Details tab.

I'm also having this issue, which isn't letting me use the date() formatting due to this. ? Also when it does jump to that, the time selector GUI doesn't work. 

Link to comment
Share on other sites

@Tom. For what it's worth, this is how I solved my problem, maybe it helps you to find your solution.

// DATE CALCULATION 
	$laserdate = date('d F Y', strtotime($feature->lendout_time));
	$lasertimestart = date('H:i:s', strtotime($feature->lendout_time));
	$lasertimestop = date('H:i:s', strtotime($feature->return_time));
	$start_time = new DateTime($feature->lendout_time);
	$since_start = $start_time->diff(new DateTime($feature->return_time));
	$minutes = $since_start->h * 60;
	$minutes += $since_start->i;
	$lasertime = gmdate("H:i:s", strtotime($feature->return_time) - strtotime($feature->lendout_time));
// RESULT
	if($feature->return_time) {
	echo "<li><span class='verdana'>{$laserdate} ->  {$studentspage->title} | {$feature->machine} => <b>{$lasertimestart} -> {$lasertimestop}</b> = {$since_start->h}:{$since_start->i}:{$since_start->s} or <font color='green'><b>{$minutes} minutes - done</b></font></span>.</li>"; 
	} else {
	echo "<li><a href='{$feature->url}'><span class='verdana'>{$laserdate} ->  {$studentspage->title} | {$feature->machine} => <b>{$lasertimestart} -> <font color='red'>busy</b></font></span>.</a></li>"; 
	};

You can see it working here below the Google calendar: https://mekano.info/en/calendar/

Link to comment
Share on other sites

  • 6 months later...

@J_Szwarga 

Thanks for the post.

If you only need to output in 12 hour format, you can probably do it like this within your template files (untested)...

# Pull the values from our page's time field...
$timeparts = FieldtypeTime::getTimeParts($page->timefield);  # Adjust name of field as needed.

# Adjust the sign
$sign = (empty($timeparts['sign']) ? '+' : '-';

# Create a time, based on the start of today, with the offset hours, mins and seconds from the timeparts.
# See: https://www.php.net/manual/en/function.strtotime.php
$time = strtotime("today $sign {$timeparts['hours']} hours {$timeparts['mins']} mins {$timeparts['secs']} secs");

# Format it for output as needed, in this case as 12hours with lowercase am/pm marker.
# See: https://www.php.net/manual/en/function.date.php
echo date("ga", $time);

 

Link to comment
Share on other sites

  • 5 months later...

Hi @netcarver thx for the great module!

Would you mind renaming the title of the module to "Time" only without the Fieldtype? It would make selecting it easier (I'm using the keyboard most of the time and it would be nice (and consistent) to type "time" instead of "fieldtype time").

KiWTh17.png

 

Another little glitch:

NZgLerG.png

The field is set to this format:

7W3tKAs.png

After selecting a time, the format is correct (eg 18:30), but initially it displays seconds (which is not wanted).

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

@netcarver Field is showing "PLACEHOLDER" when empty, is that intentional or is there a way to configure the placeholder value?

Also a default value option would be very, very neat. I'm running this on an event planner that has events almost always starting around the same time of day. Would that be hard to implement?

Running version 0.2.2, field is inside a repeater in this case.

Thanks a bunch!

inputfield_time_placeholder.png

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 9 months later...
  • 2 years later...

@netcarver
it's been two years since the last post and I wanted to politely ask if you could take another look at this module to make it PW 3.x ready?
Would be cool to have the installation without all these hints regarding incompatibility 😉
Many thanks in advance

Link to comment
Share on other sites

@Ralf

Please would you try out the new, ng branch, and let me know how it goes.

Spoiler
Various Updates
* PW 3+
* PHP 7.2+
* Modern array syntax
* Fix: Name in field type list
* Fix: Incorrect format selection
* Feat: Add appropriate placeholder based on format
* Feat: Add title attr from format description
* Chore: More consistent strings
* Chore: More consistent functions
* Chore: More type hinting

The ng branch on github.
Direct download link for the ng branch zip.

Not for production sites at the moment.

Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...