Skip to content

Commit

Permalink
fix bug and echo result with json
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyongkang committed Feb 7, 2022
1 parent 344e043 commit 2eb9c6b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 505 deletions.
Binary file modified conversion tools.alfredworkflow
Binary file not shown.
24 changes: 8 additions & 16 deletions microtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@
require_once('workflows.php');

class Time{

function __construct() {
date_default_timezone_set('PRC');
$this->workflows = new Workflows();
}

public function getTime($string){
if(empty($string)){
$title = $this->getMsecTime();
$sub_title = $this->getMsecToMescdate($title);

$this->workflows->result(1, $title, $title, $sub_title, 'icon.png');
$this->workflows->result(2, $sub_title, $sub_title, $title, 'icon.png');
set_result(1, $title, $title, $sub_title, 'icon.png');
set_result(2, $sub_title, $sub_title, $title, 'icon.png');
}else{
if(is_numeric($string)){
if(is_numeric($string) && strlen($string) == 13){
$title = $this->getMsecToMescdate($string);
}else{
$title = $this->getDateToMesc($string);
}

$this->workflows->result(1, $title, $title, $string, 'icon.png');
set_result(1, $title, $title, $string, 'icon.png');
}

echo $this->workflows->toxml();
echo_result();
}

/**
Expand All @@ -35,8 +30,7 @@ public function getTime($string){
public function getMsecTime()
{
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return $msectime;
return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
}

/**
Expand All @@ -46,15 +40,14 @@ public function getMsecToMescdate($msectime)
{
$msectime = $msectime * 0.001;
if(strstr($msectime,'.')){
sprintf("%01.3f",$msectime);
list($usec, $sec) = explode(".",$msectime);
$sec = str_pad($sec,3,"0",STR_PAD_RIGHT);
}else{
$usec = $msectime;
$sec = "000";
}
$date = date("Y-m-d H:i:s.x",$usec);
return $mescdate = str_replace('x', $sec, $date);
return str_replace('x', $sec, $date);
}

/**
Expand All @@ -64,8 +57,7 @@ public function getDateToMesc($mescdate)
{
list($usec, $sec) = explode(".", $mescdate);
$date = strtotime($usec);
$return_data = str_pad($date.$sec,13,"0",STR_PAD_RIGHT);
return $msectime = $return_data;
return str_pad($date.$sec,13,"0",STR_PAD_RIGHT);
}
}

Expand Down
13 changes: 4 additions & 9 deletions time.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@
require_once('workflows.php');

class Time{

function __construct() {
date_default_timezone_set('PRC');
$this->workflows = new Workflows();
}

public function getTime($string){
if(empty($string)){
$title = time();
$sub_title = date('Y-m-d H:i:s', time());

$this->workflows->result(1, $title, $title, $sub_title, 'icon.png');
$this->workflows->result(2, $sub_title, $sub_title, $title, 'icon.png');
set_result(1, $title, $title, $sub_title, 'icon.png');
set_result(2, $sub_title, $sub_title, $title, 'icon.png');
}else{
if(is_numeric($string)){
$title = date('Y-m-d H:i:s', $string);
}else{
$title = strtotime($string);
}

$this->workflows->result(1, $title, $title, $string, 'icon.png');
set_result(1, $title, $title, $string, 'icon.png');
}

echo $this->workflows->toxml();
echo_result();
}
}

Expand Down
45 changes: 21 additions & 24 deletions varConv.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
class VarConv{

function __construct() {
date_default_timezone_set('PRC');
$this->trans = new trans();
$this->workflows = new Workflows();
}

public function getParas($string){
$str_arr = explode(' ', $string);

if(count($str_arr)){
if (empty($str_arr[1])) {
if (empty($string)){
set_result(1, '变量转换小工具', '变量翻译(默认),变量形式转换(驼峰转下划线等)', '', 'icon.png');
}else{
$str_arr = explode(' ', $string);
if (empty($str_arr[1])) {
$type = 'g';
$para = $str_arr[0];
}else{
Expand All @@ -26,9 +25,7 @@ public function getParas($string){
if ($type == 'g') {
$trans_res = $this->trans->getTrans($para);
if ($trans_res['res'] == 'error') {
$this->workflows->result(1, '出错啦', '出错啦', $trans_res['content'], 'icon.png');
echo $this->workflows->toxml();
return;
set_result(1, '出错啦', '出错啦', $trans_res['content'], 'icon.png');
}

$res = $trans_res['res'];
Expand All @@ -37,68 +34,68 @@ public function getParas($string){

$i=1;
foreach ($trans_res as $key => $value) {
$this->workflows->result($i, $value['title'], $value['title'], $value['subtitle'], 'icon.png');
set_result($i, $value['title'], $value['title'], $value['subtitle'], 'icon.png');
$i++;
}
}elseif ($type == 'c') {
if (preg_match('/([a-z])([A-Z])/', $para)) {
$title = $this->trans->toLine($para, '_', false);
$subtitle = '下划线 => '.$para;
$this->workflows->result(1, $title, $title, $subtitle, 'icon.png');
set_result(1, $title, $title, $subtitle, 'icon.png');
$title = $this->trans->toLine($para, '-', false);
$subtitle = '中划线 => '.$para;
$this->workflows->result(2, $title, $title, $subtitle, 'icon.png');
set_result(2, $title, $title, $subtitle, 'icon.png');
$title = $this->trans->toLine($para, ' ', false);
$subtitle = '空格 => '.$para;
$this->workflows->result(3, $title, $title, $subtitle, 'icon.png');
set_result(3, $title, $title, $subtitle, 'icon.png');
}else{

if (strpos($para, ' ') !== false) {
$title = $this->trans->toLine($para, '_', false);
$subtitle = '下划线 => '.$para;
$this->workflows->result(1, $title, $title, $subtitle, 'icon.png');
set_result(1, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toLine($para, '-', false);
$subtitle = '中划线 => '.$para;
$this->workflows->result(2, $title, $title, $subtitle, 'icon.png');
set_result(2, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toHump($para, false);
$subtitle = '驼峰 => '.$para;
$this->workflows->result(3, $title, $title, $subtitle, 'icon.png');
set_result(3, $title, $title, $subtitle, 'icon.png');
}
elseif (strpos($para, '_') !== false) {
$title = $this->trans->toLine($para, '-', false);
$subtitle = '中划线 => '.$para;
$this->workflows->result(1, $title, $title, $subtitle, 'icon.png');
set_result(1, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toLine($para, ' ', false);
$subtitle = '空格 => '.$para;
$this->workflows->result(2, $title, $title, $subtitle, 'icon.png');
set_result(2, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toHump($para, false);
$subtitle = '驼峰 => '.$para;
$this->workflows->result(3, $title, $title, $subtitle, 'icon.png');
set_result(3, $title, $title, $subtitle, 'icon.png');
}
elseif (strpos($para, '-') !== false) {
$title = $this->trans->toLine($para, '_', false);
$subtitle = '下划线 => '.$para;
$this->workflows->result(1, $title, $title, $subtitle, 'icon.png');
set_result(1, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toLine($para, ' ', false);
$subtitle = '空格 => '.$para;
$this->workflows->result(2, $title, $title, $subtitle, 'icon.png');
set_result(2, $title, $title, $subtitle, 'icon.png');

$title = $this->trans->toHump($para, false);
$subtitle = '驼峰 => '.$para;
$this->workflows->result(3, $title, $title, $subtitle, 'icon.png');
set_result(3, $title, $title, $subtitle, 'icon.png');
}else{
$this->workflows->result(1, 'error', '出错啦', 'error', 'icon.png');
set_result(1, 'error', '出错啦', 'error', 'icon.png');
}
}
}
}

echo $this->workflows->toxml();
echo_result();
}


Expand Down
Loading

0 comments on commit 2eb9c6b

Please sign in to comment.